Maximum AND

Can anyone tell whats wrong in my code, I don’t know it not passing any subtask, please help,
https://www.codechef.com/viewsolution/34784243

if they x are possible then question is saying to find smaller one
but for this query
4 5
3 4 5 1
this output should be 7
but they are giving 31

how i don’t know

7 have only 3 bits as 1 in its binary, so how can this be an answer, where k=5.