import java.io.*; import java.util.*; public class Main { static HashMap searched = new HashMap(); static int[][] m; static int w; static int h; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Scanner sc = new Scanner(System.in); w = sc.nextInt(); h = sc.nextInt(); m = new int[w][h]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { m[j][i] = sc.nextInt(); } } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (searched.containsKey(i + "," + j)) { continue; } if (search(i, j)) { System.out.println("possible"); return; } } } System.out.println("impossible"); } private static boolean search(int tmpW, int tmpH) { int baseNum = m[tmpW][tmpH]; HashMap seaching = new HashMap(); HashMap tmpSearched = new HashMap(); seaching.put(tmpW + "," + tmpH, ""); String b = null; while (!seaching.isEmpty()) { String now = seaching.keySet().iterator().next(); b = seaching.get(now); seaching.remove(now); if (tmpSearched.containsKey(now)) { return true; } tmpSearched.put(now, ""); searched.put(now, ""); for (int i = 0; i < 4; i++) { String[] wh = now.split(","); int nowW = Integer.parseInt(wh[0]); int nowH = Integer.parseInt(wh[1]); if (i == 0) { if (nowH + 1 < h) { nowH = nowH + 1; } else { continue; } } else if (i == 1) { if (nowW + 1 < w) { nowW = nowW + 1; } else { continue; } } else if (i == 2) { if (nowH - 1 >= 0) { nowH = nowH - 1; } else { continue; } } else if (i == 3) { if (nowW - 1 >= 0) { nowW = nowW - 1; } else { continue; } } String tmpPlace = nowW + "," + nowH; if (baseNum == m[nowW][nowH] && !tmpPlace.equals(b)) { seaching.put(tmpPlace, now); } } } return false; } }