#include #include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } const std::vector> dxys{{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; void solve() { int h, w; std::cin >> w >> h; auto grid = vec(h, vec(w, 0)); for (auto& v : grid) { for (auto& x : v) std::cin >> x; } auto visited = vec(h, vec(w, 0)); std::function dfs = [&](int x, int y, int px, int py) { visited[x][y] = 2; for (auto [dx, dy] : dxys) { int nx = x + dx, ny = y + dy; if (nx < 0 || h <= nx || ny < 0 || w <= ny || (nx == px && ny == py) || grid[nx][ny] != grid[x][y]) continue; if (visited[nx][ny] == 2) { std::cout << "possible\n"; std::exit(0); } dfs(nx, ny, x, y); } visited[x][y] = 1; }; for (int sx = 0; sx < h; ++sx) { for (int sy = 0; sy < w; ++sy) { if (visited[sx][sy] == 0) dfs(sx, sy, -1, -1); } } std::cout << "impossible\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }