W, H = map(int, input().split()) M = [list(map(int, input().split())) for _ in range(H)] P = [[-1] * W for _ in range(H)] dir = [[0, 1], [1, 0], [-1, 0], [0, -1]] for h in range(H): for w in range(W): if P[h][w] == -1: Q = [(h, w)] Q2 = [] a = M[h][w] while Q: while Q: x, y = Q.pop() for xd, yd in dir: x1 = x + xd y1 = y + yd if 0 <= x1 < H and 0 <= y1 < W: if M[x1][y1] != a: continue if (x1,y1) == P[x][y]: continue if P[x1][y1] == -1: P[x1][y1] = (x,y) Q2.append((x1,y1)) else: print("possible") exit() Q,Q2 = Q2,Q print("impossible")