#include #define rep(i,a,b) for(int i=int(a);i P; int INF = (1LL << 30) - 1; int MOD = 1e9+7; int W,H; int M[100][100]; bool dfs(P post,P now,int value){ //cout << now.first << "," << now.second << endl; //cout << M[now.first][now.second] << endl; M[now.first][now.second] = -value; int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0}; rep(i,0,4){ int x = dx[i] + now.second, y = dy[i] + now.first; //範囲外 if(x < 0 || x >= W || y < 0 || y >= H)continue; //直前のマスには移動しない if(post.first == y && post.second == x)continue; //直前のマス以外でぶつかるところを探す if(M[y][x] == -value)return 1; if(M[y][x] == value && dfs(now, P(y,x), value))return 1; } return 0; } main(){ cin >> W >> H; rep(i,0,H)rep(j,0,W)cin >> M[i][j]; rep(k,1,1001)rep(i,0,H)rep(j,0,W){ if(M[i][j] == k){ //cout << i << " " << j << endl; if(dfs( P(-1,-1), P(i,j) , k)){ cout << "possible" << endl; return 0; } } } /* rep(i,0,H)rep(j,0,W){ cout << M[i][j] << " \n"[j == W-1]; } */ cout << "impossible" << endl; }