#define REP(i,n) for(int i=0; i<(int)(n); i++) #include #include #include inline int getInt(){ int s; scanf("%d", &s); return s; } #include using namespace std; const int _dx[] = {0,1,0,-1}; const int _dy[] = {-1,0,1,0}; #define IN(x,s,g) ((x) >= (s) && (x) < (g)) #define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h))) int main(){ const int w = getInt(); const int h = getInt(); vector > g(h, vector(w)); REP(i,h) REP(j,w) g[i][j] = getInt(); vector > f(h, vector(w)); function dfs = [&](int y, int x, int py, int px){ if(f[y][x]) return true; f[y][x] = true; REP(i,4){ const int xx = x + _dx[i]; const int yy = y + _dy[i]; if(ISIN(xx, yy, w, h) && (xx != px || yy != py) && g[y][x] == g[yy][xx]) if(dfs(yy, xx, y, x)) return true; } return false; }; bool ans = false; REP(i,h) REP(j,w) if(!f[i][j]) ans |= dfs(i, j, -1, -1); puts(ans ? "possible" : "impossible"); return 0; }