#include #include "bits/stdc++.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; const int INF = 1e8; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) using namespace std; typedef pair P; int field[101][101]; bool visited[101][101]; int w, h, now; int xt[] = { 1, 0, -1, 0 }; int yt[] = { 0, 1, 0, -1 }; bool judge = false; bool dfs(int y, int x, int pre_x, int pre_y) { if (visited[y][x]) { /*cout << x << " " << y << " " << pre_x << " " << pre_y << endl;*/ return true; } visited[y][x] = true; for (int i = 0; i < 4; i++) { int nx = x + xt[i]; int ny = y + yt[i]; if (pre_x == nx && pre_y == ny) { continue; } if (nx < w && nx >= 0 && ny < h && ny >= 0 && field[ny][nx] == now) { if(dfs(ny, nx, x, y)){ return true; } } } return false; } int main() { cin >> w >> h; int tmp = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> tmp; field[i][j] = tmp; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (!visited[i][j]) { now = field[i][j]; if(dfs(i, j, -1, -1)){ judge = true; } } } } if (judge) { cout << "possible" << endl; } else { cout << "impossible" << endl; } return 0; }