w, h = map(int, input().split()) m = [list(map(int, input().split())) for _ in range(h)] pre = [[None] * w for _ in range(h)] ok = False for i in range(h): for j in range(w): if pre[i][j] is None: num = m[i][j] pre[i][j] = i, j q = [(i, j)] while q: x, y = q.pop() for nx, ny in (x-1, y), (x+1, y), (x, y-1), (x, y+1): if 0 <= nx < h and 0 <= ny < w and m[nx][ny] == num and (nx, ny) != pre[x][y]: if pre[nx][ny] is None: pre[nx][ny] = x, y q.append((nx, ny)) else: ok = True print('im' * (not ok) + 'possible')