#!/usr/bin/env python3.8 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools # %% W, H = map(int, readline().split()) M = tuple(map(int, read().split())) # %% N = W * H graph = [[] for _ in range(N)] for i, j in itertools.product(range(W - 1), range(H)): x = W * j + i if M[x] == M[x + 1]: graph[x].append(x + 1) graph[x + 1].append(x) for i, j in itertools.product(range(W), range(H - 1)): x = W * j + i if M[x] == M[x + W]: graph[x].append(x + W) graph[x + W].append(x) # %% visited = [False] * N found = False for i in range(N): if visited[i]: continue visited[i] = True V = 1 E = 0 stack = [i] while stack: v = stack.pop() E += len(graph[v]) for w in graph[v]: if visited[w]: continue V += 1 visited[w] = True stack.append(w) E //= 2 if V <= E: found = True break print('possible' if found else 'impossible')