#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if(y < x) x = y; } template static void amax(T &x, U y) { if(x < y) x = y; } int main() { int H; int W; while(~scanf("%d%d", &H, &W)) { vector > A(H, vector(W)); for(int i = 0; i < H; ++ i) for(int j = 0; j < W; ++ j) scanf("%d", &A[i][j]); int ans = INF; vector> flipped(H, vector(W)); rep(s, 1 << (H + W - 1)) { rep(i, H) flipped[i][0] = s >> i & 1; rep(j, W - 1) flipped[0][1 + j] = s >> (H + j) & 1; bool ok = true; rer(i, 1, H) rer(j, 1, W) { int x = A[i - 1][j - 1]; rer(dy, -1, 1) rer(dx, -1, 1) if(!(dy == 1 && dx == 1)) { int yy = i - 1 + dy, xx = j - 1 + dx; if(0 <= yy && yy < H && 0 <= xx && xx < W) x ^= flipped[yy][xx]; } if(i >= H || j >= W) ok &= x == 0; else flipped[i][j] = x; } if(ok) { int cnt = 0; rep(i, H) rep(j, W) cnt += flipped[i][j]; amin(ans, cnt); } } if(ans == INF) puts("Impossible"); else printf("%d\n", ans); } return 0; }