import math._ import collection.mutable.Stack object Main { def calc(rows: Int, cols: Int, g: Array[Array[Int]]): Boolean = { val used = Array.fill(rows, cols)(false) for (i <- 0 to rows-1; j <- 0 to cols-1 if !used(i)(j)) { val num = g(i)(j) val s = new Stack[(Int, Int, Int, Int)] s.push((i, j, -1, -1)) while (!s.isEmpty) { val (r, c, pr, pc) = s.pop if (used(r)(c)) return true used(r)(c) = true for ((dr, dc) <- Array((1, 0), (0, 1), (-1, 0), (0, -1))) { val r2 = r + dr val c2 = c + dc if (0 <= r2 && r2 < rows && 0 <= c2 && c2 < cols) { if (g(r2)(c2) == num && (r2, c2) != (pr, pc)) { s.push((r2, c2, r, c)) } } } } } false } def main(args: Array[String]) = { val sc = new java.util.Scanner(System.in) val W, H = sc.nextInt val g = Array.fill(H, W)(sc.nextInt) if (calc(H, W, g)) println("possible") else println("impossible") } }