#include using namespace std; #define W_MAX 100 #define H_MAX 100 int W, H; int field[H_MAX][W_MAX]; bool used[H_MAX][W_MAX]; const int dy[] = {-1, 0, 1, 0}; const int dx[] = {0, 1, 0, -1}; bool dfs(int y, int x, const int& M) { used[y][x] = 1; int cnt = 0; for (int i = 0; i < 4; i++) { int ny = y + dy[i]; int nx = x + dx[i]; if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue; if (used[ny][nx] || field[ny][nx] != M) { if (field[ny][nx] == M) if (++cnt) return 1; continue; } if (dfs(ny, nx, M)) return 1; } return 0; } int main() { scanf("%d%d", &W, &H); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { scanf("%d", &field[i][j]); } } bool f = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (used[i][j]) continue; if (dfs(i, j, field[i][j])) { f = 1; break; } } if (f) break; } printf("%s\n", f ? "possible" : "impossible"); return 0; }