#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair P; const ll INF = 1ll<<29; const ll MOD = 1000000007; const double EPS = 1e-10; int w, h; int maps[100][100]; bool done[100][100]; bool dfs(int num, int x, int y, int prev) { if (done[y][x]) return true; done[y][x] = true; static int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; REP(i, 4) { int nx = x + dx[i], ny = y + dy[i]; if (!(nx >= 0 && nx < w && ny >= 0 && ny < h)) continue; if (maps[ny][nx] != num) continue; if (ny * w + nx == prev) continue; if (dfs(num, nx, ny, y * w + x)) return true; } return false; } int main() { cin >> w >> h; REP(i, h) REP(j, w) scanf("%d", &maps[i][j]); bool ans = false; FOR(i, 1, 1000) { memset(done, 0, sizeof(done)); REP(y, h) REP(x, w) { if (maps[y][x] == i && !done[y][x]) { if (dfs(i, x, y, -1)) ans = true; } } } puts(ans ? "possible" : "impossible"); return 0; }