#include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair pii; typedef tuple tiii; typedef vector vi; #define REP(i,x) for(int i=0;i<(int)(x);i++) #define ALL(container) (container).begin(), (container).end() int f[200][200]; int visit[200][200]; int main(int argc, char *argv[]){ ios::sync_with_stdio(false); int w,h; cin >> w >> h; REP(i, 200) REP(j, 200) f[i][j] = 0; REP(i, 200) REP(j, 200) visit[i][j] = 0; REP(i, h) REP(j, w) { int v; cin >> v; f[i+1][j+1] = v; } pii shifts[] = {{1,0},{0,1},{-1,0},{0,-1}}; REP(i, h) REP(j, w) { int sh = i + 1; int sw = j + 1; REP(k, 200) REP(l, 200) visit[k][l] = 0; queue q; q.push(make_tuple(sw,sh,-1)); visit[sh][sw] = 1; int num = f[sh][sw]; while(!q.empty()) { const auto t = q.front(); q.pop(); int current = visit[get<1>(t)][get<0>(t)]; for(int s = 0;s < 4;s++) { if(s == get<2>(t)) { continue; } auto x = get<0>(t) + shifts[s].first; auto y = get<1>(t) + shifts[s].second; if(f[y][x] != num) { continue; } if(visit[y][x]) { cout << "possible" << endl; return 0; } else { visit[y][x] = current + 1; q.push(make_tuple(x,y,(s + 2) % 4)); } } } } cout << "impossible" << endl; return 0; }