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|[z+n,z+1].any?{|w|z%n<=w%n&&a[z/n][z%n]==a[w/n][w%n]&&($p[v=r(w)]=r z)==v}}?'':'im','possible'