#include #include #include #include #include typedef long long ll; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) int w, h; int b[110][110]; int used[110][110]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main(void){ cin >> w >> h; rep(i, h)rep(j, w) cin >> b[i][j]; rep(i, h)rep(j, w){ rep(a, 110)rep(b, 110)used[a][b] = 0; queue > q; queue v; int num = b[i][j]; used[i][j] = 1;//逆戻りを防ぐように q.push(make_pair(i, j));//スタート v.push(-1); while(!q.empty()){ auto now = q.front(); q.pop(); auto from = v.front(); v.pop(); rep(k, 4){ if(from == (k + 2) % 4 && from != -1) continue;//来た方向に戻るのを防ぐ int y = now.first + dy[k], x = now.second + dx[k]; if(y < 0 || h <= y || x < 0 || w <= x) continue; if(used[y][x] == 1){ /* printf("%d %d %d %d\n", i, j, y ,x); rep(s, h){ rep(t, w){ printf("%d ", used[s][t]); } printf("\n"); } */ printf("possible\n"); return 0; } if(b[y][x] == num && used[y][x] == 0){ q.push(make_pair(y, x)); v.push(k); used[y][x] = 1; } } } } printf("impossible\n"); return 0; }