import sys #sys.setrecursionlimit(n) import heapq import re import bisect import random import math import itertools from collections import defaultdict, deque from copy import deepcopy w, h = map(int, input().split()) m = [[int(i) for i in input().split()] for i in range(h)] d = [[0 for _ in range(w)] for _ in range(h)] dist = ((1,0), (-1,0), (0,1), (0,-1)) def solve(x, y): q = deque() q.append((x << 32) + (y << 16) + (0xFF << 8) + 0xFF) d[y][x] = True while (q): v = q.popleft() vx = v >> 32 vy = (v >> 16) & 0xFF ox = (v >> 8) & 0xFF oy = v & 0xFF for fdist in dist: ny = vy + fdist[0] nx = vx + fdist[1] if nx == ox and ny == oy: continue if nx >= w or nx < 0 or ny >= h or ny < 0: continue if m[ny][nx] != m[y][x]: continue if d[ny][nx]: return True d[ny][nx] = True q.append((nx << 32) + (ny << 16) + (vx << 8) + vy) return False flag = False for y in range(h): for x in range(w): if d[y][x]: continue if solve(x, y): flag = True break print("possible" if flag else "impossible")