Most Frequent Row XORMedium

Most Frequent Row XOR

MediumPractice library · +20 XPmatrixhash mapfrequency

Given a binary matrix (containing only 0s and 1s), where each row represents a binary number, calculate the XOR sum of all rows. Then, find the binary number that appears most frequently as a row XOR sum. If there are multiple such numbers with the same highest frequency, return the largest one. The matrix dimensions are M x N. Each row is treated as an N-bit binary number.

Input

The first line contains two integers M and N. The next M lines each contain N binary digits (0 or 1), representing the rows of the matrix.

Output

Print a single integer representing the most frequent row XOR sum. This sum should be interpreted as an N-bit binary number and printed as a decimal integer.

Constraints

1 <= M, N <= 1000. The total number of elements in the matrix (M*N) is at most 200000.

Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests

Example 1

Input
3 4
1010
0110
1010
Output
10

Row values are 10, 6, 10. '10' appears twice, '6' once. The most frequent is 10.

Example 2

Input
4 2
11
01
10
11
Output
3

Row values are 3, 1, 2, 3. '3' appears twice, '1' and '2' once. The most frequent is 3.

Hints