#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int m[110][110]; bool b[110][110] = { false }; int b1[4] = { 0,0,-1,1 }; int b2[4] = { -1,1,0,0 }; int main() { int w, h; cin >> w >> h; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> m[i][j]; } } stack> st; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (!b[i][j]) { b[i][j] = true; st.push(make_tuple(i, j, m[i][j], -1, -1)); } while (!st.empty()) { tuple t = st.top(); st.pop(); int x = get<0>(t); int y = get<1>(t); int num = get<2>(t); int ax = get<3>(t); int ay = get<4>(t); for (int i = 0; i < 4; i++) { if (x + b1[i] < 0 || y + b2[i] < 0 || x + b1[i] >= h || y + b2[i] >= w)continue; if (num == m[x + b1[i]][y + b2[i]]) { if (!b[x + b1[i]][y + b2[i]]) { st.push(make_tuple(x + b1[i], y + b2[i], num, x, y)); b[x + b1[i]][y + b2[i]] = true; } else if (ax != x + b1[i] || ay != y + b2[i]) { cout << "possible" << endl; return 0; } } } } } } cout << "impossible" << endl; }