XOR Groups

Erase cells from an N by M grid in increasing value order and after each erasure report the maximum sum of XOR values of the connected groups.

Medium6Union-findSimulationBit manipulationNo attempts yetTime limit2sMemory limit512 MB

Problem

An N×MN \times M grid holds one number in every cell, and all of the numbers are different. Among the cells still on the board, cells that touch up, down, left, or right belong to the same XOR group, and the value of a group is the XOR of every number in it. A missing cell in between breaks the link, so one board can hold several XOR groups. The score of the board is the sum of the values of all XOR groups.

Every cell is on the board at the start. You then erase cells one at a time, always the cell holding the smallest number that is left. Each erasure changes the groups and the score. Print the largest score over the starting board before any erasure together with every board that follows an erasure.

Input

The first line has NN and MM. (1N,M1,0001 \le N, M \le 1{,}000)

Each of the next NN lines has the MM numbers of row ii of the grid, separated by spaces. Every number is an integer between 00 and 1,000,0001{,}000{,}000, and all numbers in the grid are different.

Output

Print the largest score on the first line.