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