#include #include #include #include #define W_MAX 100 #define H_MAX 100 #define T_USED 10000 using namespace std; enum Way { None = 0, Right, Left, Up, Down }; int W, H, M[H_MAX + 2][W_MAX + 2], t[H_MAX + 2][W_MAX + 2]; bool update(int x, int y, int m, Way from) { if (M[y][x] == m && t[y][x] >= T_USED) return true; else if (M[y][x] == m) t[y][x] = T_USED; else return false; if (from != Left && update(x - 1, y, m, Right)) return true; if (from != Right && update(x + 1, y, m, Left)) return true; if (from != Up && update(x, y - 1, m, Down)) return true; if (from != Down && update(x, y + 1, m, Up)) return true; return false; } bool calc() { for (int y = 1; y <= H; ++y) for (int x = 1; x <= W; ++x) if (t[y][x] != T_USED && update(x, y, M[y][x], None)) return true; return false; } int main() { cin >> W >> H; for (int y = 1; y <= H; ++y) for (int x = 1; x <= W; ++x) { cin >> M[y][x]; t[y][x] = 0; } for (int y = 0; y <= H + 1; ++y) { M[y][0] = M[y][W + 1] = t[y][0] = t[y][W + 1] = 0; } for (int x = 0; x <= W + 1; ++x) { M[0][x] = M[H + 1][x] = t[0][x] = t[H + 1][x] = 0; } if (calc()) cout << "possible" << endl; else cout << "impossible" << endl; return 0; }