#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define endl '\n' #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) typedef long long ll; typedef pair P; typedef unsigned int uint; typedef unsigned long long ull; struct pairhash { public: template size_t operator()(const pair &x) const { size_t seed = hash()(x.first); return hash()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2); } }; const int inf = 1000000009; int m[102][102]; bool used[102][102]; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; bool dfs(int x, int y, int prevx, int prevy) { used[x][y] = true; for (int i = 0; i < 4; i++) { int X = x + dx[i], Y = y + dy[i]; if (!(X == prevx && Y == prevy) && m[X][Y] == m[x][y]) { if (used[X][Y]) return true; if (dfs(X, Y, x, y)) return true; } } return false; } bool solve(int h, int w) { for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (!used[i][j]) { if (dfs(i, j, -1, -1)) return true; } } } return false; } int main() { int w, h; scanf("%d%d", &w, &h); memset(m, 0, sizeof(m)); memset(used, false, sizeof(used)); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { scanf("%d", &m[i][j]); } } printf("%s\n", solve(h, w) ? "possible" : "impossible"); }