#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int DY[4] = {-1, 0, 0, 1}; const int DX[4] = { 0,-1, 1, 0}; const int MAX_H = 100; const int MAX_W = 100; struct Coord { int y; int x; int dist; Coord(int y = -1, int x = -1, int dist = -1){ this->y = y; this->x = x; this->dist = dist; } }; int w, h; int field[MAX_H][MAX_W]; int oy, ox; int checkCount; bool success; int checkField[MAX_H][MAX_W]; void dfs(int y, int x, int dist, int num){ if(success) return; if(field[y][x] != num) return; if(y == oy && x == ox && dist >= 4){ success = true; return; } if(checkField[y][x] == checkCount) return; checkField[y][x] = checkCount; for(int i = 0; i < 4; i++){ int ny = y + DY[i]; int nx = x + DX[i]; if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue; dfs(ny, nx, dist+1, num); } } int main(){ cin >> w >> h; memset(field, -1, sizeof(field)); memset(checkField, -1, sizeof(checkField)); success = false; checkCount = 0; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ cin >> field[y][x]; } } for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ int num = field[y][x]; oy = y; ox = x; checkCount++; dfs(y, x, 0, num); } } if(success){ cout << "possible" << endl; }else{ cout << "impossible" << endl; } return 0; }