#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int w, h; int bd[128][128]; int vis[128][128]; int dy[] = {0, 1, 0, -1}; int dx[] = {1, 0, -1, 0}; bool dfs(int y, int x, int py, int px) { if (vis[y][x] == -1) return true; vis[y][x] = -1; for (int k = 0; k < 4; k++) { int y2 = y + dy[k]; int x2 = x + dx[k]; if (x2 < 0 || x2 >= w) continue; if (y2 < 0 || y2 >= h) continue; if (y2 == py && x2 == px) continue; if (bd[y2][x2] != bd[y][x]) continue; if (dfs(y2, x2, y, x)) return true; } vis[y][x] = 1; return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> w >> h; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> bd[i][j]; bool ck = false; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (vis[i][j]) continue; ck |= dfs(i, j, -1, -1); } } if (ck) cout << "possible" << endl; else cout << "impossible" << endl; return 0; }