#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int w,h;
    cin>>w>>h;
    vector<vector<int> >m(h,vector<int>(w));
    for(int i = 0;i<h;i++) for(int j  = 0;j<w;j++) cin>>m[i][j];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};

    deque<pair<pair<int,int>,pair<int,int> > > que;
    vector<vector<int> > vis(h,vector<int>(w,0));
    bool fn = false;
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            if(vis[i][j]) continue;
            int now = m[i][j];
            que.push_back(make_pair(make_pair(i,j),make_pair(-1,-1)));
            while(que.size()){
                int ni = que.front().first.first;
                int nj = que.front().first.second;
                int pi = que.front().second.first;
                int pj = que.front().second.second;
                que.pop_front();
                for(int k = 0;k<4;k++){
                    int nni = ni + dx[k];
                    int nnj = nj + dy[k];
                    if(nni<0||nni>=h||nnj<0||nnj>=w) continue;
                    if(nni==pi&&nnj==pj) continue;
                    if(m[ni][nj]!=m[nni][nnj]) continue;
                    if(vis[nni][nnj]){
                        fn = true;
                    }else{
                        vis[nni][nnj] = 1;
                        que.push_back(make_pair(make_pair(nni,nnj),make_pair(ni,nj)));
                    }
                }
            }
        }
    }
    if(fn) cout<<"possible\n";
    else cout<<"impossible\n";
}