#include "bits/stdc++.h" #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = MOD - 1; const ll LLINF = 4e18; vector> m; vector> visited; int w, h; const int dx[] = {0,-1,0,1}, dy[] = {1,0,-1,0}; bool dfs(int a, int b) { typedef tuple T; stack sta; sta.push({a, b, -1, -1}); while (!sta.empty()) { T p = sta.top(); sta.pop(); int x = get<0>(p), y = get<1>(p), parx = get<2>(p), pary = get<3>(p); visited[x][y] = true; for (int i = 0; i < 4; i++) { if (x + dx[i] >= 0 && x + dx[i] < h && y + dy[i] >= 0 && y + dy[i] < w) { if (x + dx[i] == parx && y + dy[i] == pary) continue; if (m[x + dx[i]][y + dy[i]] == m[x][y]) { if (visited[x + dx[i]][y + dy[i]]) { return true; } else { sta.push({x + dx[i],y + dy[i],x,y}); } } } } } return false; } int main() { cin >> w >> h; m.resize(h, vector(w)); visited.resize(h, vector(w, false)); REP(i, h) { REP(j, w) { cin >> m[i][j]; } } REP(i, h) { REP(j, w) { if (!visited[i][j] && dfs(i, j)) { puts("possible"); return 0; } } } puts("impossible"); getchar(); getchar(); }