This is just a guess, but ...
Replace this:
if(M[i][j]!=(M[j][i] || -M[j][i]))
With this:
if(M[i][j] != M[j][i] && M[i][j] != -M[j][i]))
when you OR two integers using || use treat them as boolean values: so
(M[j][i] || -M[j][i])
Will return true or false - and probably doesn't match your cell contents.