#include #include #include using namespace std; const int DX[] = {1, 0, -1, 0}; const int DY[] = {0, 1, 0, -1}; int W, H; int M[100][100]; bool visited[100][100]; int main() { cin >> W >> H; for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { cin >> M[x][y]; } } for (int x = 0; x < W; x++) { for (int y = 0; y < H; y++) { if (!visited[x][y]) { queue > Q; Q.push(make_pair(x + y * W, -1)); while (!Q.empty()) { pair p = Q.front(); Q.pop(); int cx = p.first % W, cy = p.first / W; if (visited[cx][cy]) { cout << "possible" << endl; return 0; } visited[cx][cy] = true; for (int d = 0; d < 4; d++) { if (p.second == (d + 2) % 4) { continue; } int xx = cx + DX[d], yy = cy + DY[d]; if (0 <= xx && xx < W && 0 <= yy && yy < H && M[xx][yy] == M[cx][cy]) { Q.push(make_pair(xx + yy * W, d)); } } } } } } cout << "impossible" << endl; return 0; }