#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; int W, H; int field[105][105]; vector G[10005]; int vx[4] = {0,0,1,-1}; int vy[4] = {1,-1,0,0}; int xx[1005]; bool check(int s){ int N = W*H; vector visited(N, 0); queue< pair > que; que.push(make_pair(s, -1)); while(!que.empty()){ pair p = que.front(); que.pop(); visited[p.first] = 1; rep(i,G[p.first].size()){ if(G[p.first][i] == p.second) continue; if(visited[G[p.first][i]] == 1) return true; que.push(make_pair(G[p.first][i], p.first)); } } return false; } int main(){ cin >> W >> H; rep(i,H){ rep(j,W){ cin >> field[i][j]; } } rep(i,1005){ xx[i] = -1; } rep(i,H){ rep(j,W){ xx[field[i][j]] = i*W+j; rep(k,4){ int nx = j+vx[k], ny = i+vy[k]; if(0<=nx && nx= 0){ if(check(xx[i])){ cout << "possible" << endl; return 0; } } } cout << "impossible" << endl; return 0; }