W, H = gets.split.map(&:to_i) M = (1..H).map {gets.split.map(&:to_i)} DP = Array.new(H) {Array.new(W, false)} def f(i, j, p, q) if not i.between?(0, H - 1) or not j.between?(0, W - 1) or M[i][j] != M[p][q] false elsif DP[i][j] true else DP[i][j] = true [[i, j + 1], [i + 1, j], [i, j - 1], [i - 1, j]].any? {|a, b| [a, b] != [p, q] and f(a, b, i, j)} end end ans = if (0...H).to_a.product((0...W).to_a).any? {|i, j| not DP[i][j] and f(i, j, i, j)} "possible" else "impossible" end puts ans