import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int[][] field; static boolean[][] visited; static int h; static int w; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); w = sc.nextInt(); h = sc.nextInt(); field = new int[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { field[i][j] = sc.nextInt(); } } visited = new boolean[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (check(i, j, -1, -1, new HashSet(), field[i][j])) { System.out.println("possible"); return; } } } System.out.println("impossible"); } static boolean check(int r, int c, int pr, int pc, HashSet used, int value) { if (used.contains(r * w + c)) { return true; } if (visited[r][c] || value != field[r][c]) { return false; } visited[r][c] = true; used.add(r * w + c); if (r > 0) { if (r - 1 != pr || c != pc) { if (check(r - 1, c, r, c, used, value)) { return true; } } } if (r < h - 1) { if (r + 1 != pr || c != pc) { if (check(r + 1, c, r, c, used, value)) { return true; } } } if (c > 0) { if (r != pr || c - 1 != pc) { if (check(r, c - 1, r, c, used, value)) { return true; } } } if (c < w - 1) { if (r != pr || c + 1 != pc) { if (check(r, c + 1, r, c, used, value)) { return true; } } } used.remove(r * w + c); return false; } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }