#include using namespace std; class UnionFind { private: int n; vector a; public: UnionFind(int n) : n(n), a(n, -1) {} int find(int x) {return a[x] < 0 ? x : (a[x] = find(a[x]));} bool equal(int x, int y) {return find(x) == find(y);} void unite(int x, int y) { x = find(x), y = find(y); if (x == y) return; if (a[x] > a[y]) swap(x, y); a[x] += a[y]; a[y] = x; --n; } int size() {return n;} int size(int x) {return -a[find(x)];} }; int main() { int w, h; cin >> w >> h; vector> m(h, vector(w)); for (auto& i : m) { for (int& j : i) cin >> j; } UnionFind uf(w * h); bool possible = false; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (i != h - 1 && m[i][j] == m[i + 1][j]) { if (uf.equal(i * w + j, i * w + j + w)) possible = true; uf.unite(i * w + j, i * w + j + w); } if (j != w - 1 && m[i][j] == m[i][j + 1]) { if (uf.equal(i * w + j, i * w + j + 1)) possible = true; uf.unite(i * w + j, i * w + j + 1); } } } cout << (possible ? "possible" : "impossible") << endl; }