#include "bits/stdc++.h" using namespace std; typedef long long Int; #define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i)) int W, H; int a[110][110]; vector g[10000]; bool vis[10000]; bool cycle = false; void dfs(int p, int prev) { if (vis[p]) { cycle = true; return; } vis[p] = true; REP(i, g[p].size()) if (prev != g[p][i]) { dfs(g[p][i], p); } } int main() { cin >> W >> H; REP(i, H) REP(j, W) cin >> a[i][j]; int di[] = {0, 1, 0, -1}; int dj[] = { 1, 0, -1, 0 }; REP(i, H) REP(j, W) { REP(k, 4) { int ni = i + di[k]; int nj = j + dj[k]; if (0 <= ni && ni < H && 0 <= nj && nj < W && a[i][j] == a[ni][nj]) { int p1 = i * W + j; int p2 = ni * W + nj; g[p1].push_back(p2); } } } cycle = false; REP(p, H * W) if (!vis[p]) { dfs(p, -1); } cout << (cycle ? "possible " : "impossible ") << endl; }