#!/usr/bin/env python3 import array import collections import itertools REC_LIMIT = 10000 DELTAS = [(1, 0), (-1, 0), (0, 1), (0, -1)] UNDEF = (-1, -1) class Solver(object): def __init__(self, width, height, field): self.width = width self.height = height self.field = field self.visited = collections.defaultdict(bool) self.pred = collections.defaultdict(lambda: UNDEF) def in_field(self, r, c): return 0 <= r < self.height and 0 <= c < self.width def in_cycle(self, r0, c0, num): self.visited[(r0, c0)] = True q = collections.deque() q.append((r0, c0)) while q: (r1, c1) = q.pop() for dr, dc in DELTAS: (r, c) = (r1 + dr, c1 + dc) if not self.in_field(r, c): continue elif self.field[r][c] != num: continue if self.visited[(r, c)]: if self.pred[(r1, c1)] != (r, c): return True else: continue self.visited[(r, c)] = True self.pred[(r, c)] = (r1, c1) q.append((r, c)) return False def judge(self): rcs = itertools.product(range(self.height), range(self.width)) for r, c in rcs: if not self.visited[(r, c)]: answer = self.in_cycle(r, c, self.field[r][c]) if answer: return True else: return False def main(): width, height = map(int, input().split()) field = [array.array("I", map(int, input().split())) for _ in range(height)] solver = Solver(width, height, field) print("possible" if solver.judge() else "impossible") if __name__ == '__main__': main()