#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using vb = vector; using vvb = vector; using vd = vector; using vs = vector; using pii = pair; using pll = pair; using pdd = pair; using vpii = vector; using vpll = vector; using vpdd = vector; const int inf = (1 << 30) - 1; const ll INF = 1LL << 60; //const int MOD = 1000000007; const int MOD = 998244353; int dy[4] = { 0, 1, 0, -1 }; int dx[4] = { 1, 0, -1, 0 }; bool dfs(vvi& a, vvb& visit, int y, int x, int dir, int h, int w) { visit[y][x] = true; bool ret = false; for (int i = 0; i < 4; i++) { if (i == (dir + 2) % 4) continue; int x2 = x + dx[i]; int y2 = y + dy[i]; if (y2 < 0 || y2 > h - 1 || x2 < 0 || x2 > w - 1) continue; if (a[y2][x2] != a[y][x]) continue; if (visit[y2][x2]) return true; if (!visit[y2][x2]) { ret = dfs(a, visit, y2, x2, i, h, w); if (ret) return true; } } return false; } int main() { int h, w; cin >> w >> h; vvi a(h, vi(w)); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { cin >> a[y][x]; } } vvb visit(h, vb(w, false)); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (visit[y][x]) continue; if (dfs(a, visit, y, x, -11, h, w)) { cout << "possible" << endl; return 0; } } } cout << "impossible" << endl; return 0; }