import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static final int UNVISITED = 0; public static final int VISITING = 1; public static final int VISITED = 2; public static final int[][] move_dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; public static boolean in_range(int x, int y, int W, int H){ return 0 <= x && x < W && 0 <= y && y < H; } public static boolean dfs(int x, int y, int px, int py, int H, int W, int[][] board, int[][] visited){ //System.out.println(y + " " + x + " " + board[y][x]); visited[y][x] = VISITING; for(final int[] move : move_dirs){ final int nx = x + move[0]; final int ny = y + move[1]; if(!in_range(nx, ny, W, H)){ continue; } if(board[y][x] != board[ny][nx]){ continue; } if(ny == py && nx == px){ continue; } if(visited[ny][nx] == UNVISITED){ if(dfs(nx, ny, x, y, H, W, board, visited)){ visited[y][x] = VISITED; return true; } }else if(visited[ny][nx] == VISITING){ visited[y][x] = VISITED; return true; } } visited[y][x] = VISITED; return false; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int W = sc.nextInt(); final int H = sc.nextInt(); int[][] board = new int[H][W]; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ board[i][j] = sc.nextInt(); } } int[][] visited = new int[H][W]; for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ if(visited[y][x] != UNVISITED){ continue; } if(dfs(x, y, -1, -1, H, W, board, visited)){ System.out.println("possible"); return; } } } System.out.println("impossible"); } }