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}+[[]] i=0...m*n $p=i.to_a print i.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'