My logic is that

if(n*m) is even then all the freq of distinct element must be even
else if(n*m is odd) then count the elements having odd freq and if we have more than 1 count

i,e, we have more than 2 elements having odd freq then print -1

else normally solve.

. Can you please check my solution why it gives WA

Please help me and tell me where I am doing mistake