#!/usr/bin/env python3 import sys input = sys.stdin.readline w, h = map(int, input().split()) field = [] visited = [[0] * (w+2) for _ in range(h+2)] field.append([-1] * (w + 2)) for _ in range(h): line = [-1] + [int(item) for item in input().split()] + [-1] field.append(line) field.append([-1] * (w + 2)) delta = [(1, 0), (0, 1), (-1, 0), (0, -1)] def dfs(sx, sy): st = [(sx, sy, -1, -1)] c = field[sx][sy] visited[sx][sy] = 1 while st: x, y, px, py = st.pop() for dx, dy in delta: if x + dx == px and y + dy == py: continue if field[x + dx][y + dy] == c: if not visited[x + dx][y + dy]: visited[x + dx][y + dy] = 1 st.append((x+dx, y+dy, x, y)) elif visited[x + dx][y + dy]: print("possible") exit() for i in range(1, 1+h): for j in range(1, 1+w): if visited[i][j]: continue dfs(i, j) print("impossible")