The Lights Going On and Off

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a grid of lights with $R$ rows ($1 < R < 30$), where each row contains $L$ lights ($1 \le L < 8$). Every light is either on or off. The topmost row is row $R$ and the bottom-most row is row $1$.

Beside every row except the topmost one (row $R$) there is a button. The button beside row $k$ (where $1 \le k < R$) may be pushed.

Pushing the button beside row $k$ replaces each light of row $k$ with the exclusive-or of that light and the light directly above it in row $k+1$. Concretely, for column $i$ (where $1 \le i \le L$): if the lights in column $i$ of row $k$ and row $k+1$ are the same (both on or both off), the light in column $i$ of row $k$ becomes off; if they differ, it becomes on.

For example, with $L = 4$:

Column 1Column 2Column 3Column 4
Row $k+1$ononoffoff
Row $k$ beforeonoffonoff
Row $k$ afteroffononoff

Each button may be pushed at most once, but the buttons may be pushed in any order. Determine how many different light patterns the bottom row (row $1$) can show, over every possible choice and ordering of button pushes.

Input

The first line contains the integer $R$, the number of rows. The second line contains the integer $L$, the number of lights in each row. The next $R$ lines each contain $L$ integers separated by single spaces, where $0$ means a light is off and $1$ means it is on. These $R$ lines are given from top to bottom: the first of them describes row $R$, the next describes row $R-1$, and so on, with the last line describing the bottom row (row $1$).

Output

Output a single integer: the number of distinct light patterns that the bottom row can display.