#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF (1<<29) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define uniq(v) v.erase(unique(all(v)),v.end()) int n, m; int b[8][8]; int dy[] = { 0,-1,0,1,0 ,1,1,-1,-1 }; int dx[] = { 0,0,-1,0,1 ,1,-1,1,-1 }; void put(int y,int x,int a[][8]) { rep(k, 9) { int ny = y + dy[k]; int nx = x + dx[k]; if (0 <= nx&&nx> n >> m; rep(i,n) { rep(j, m) { cin >> b[i][j]; } } int ans = INF; rep(i, 1 << n+m - 1) { int c[8][8]; memcpy(c, b, sizeof(c)); int cnt = 0; rep(j, n+m-1) if(i>>j&1){ cnt++; if (j < m)put(0, j, c); else put(j - m + 1, 0, c); } rep(y, n-1)rep(x,m-1)if(c[y][x]) { cnt++; put(y + 1, x + 1, c); } bool ok = true; rep(y, n)rep(x, m)if (c[y][x])ok = false; if (ok)ans = min(ans, cnt); } if (ans == INF)cout << "Impossible" << endl; else cout << ans << endl; return 0; }