def r u;u==$p[u]?u:$p[u]=r($p[u]);end n,m=gets.split.map &:to_i a=(0..m).map{gets.split.map &:to_i} $p=(0...m*n).to_a print (0...m).any?{|x|(0...n).any?{|y| [[x+1,y],[x,y+1]].any?{|z,w| a[x][y]==a[z][w]&&( u=r x*n+y v=r z*n+w $p[u]=v u==v ) } }}?'':'im','possible'