import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; /** * yukicoder no.13 * @author scache * */ public class Main { public static void main(String[] args) { Main p = new Main(); } public Main() { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int h = sc.nextInt(); int[][] field = new int[h+2][w+2]; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ field[i][j] = sc.nextInt(); } } solve(field); } public void solve(int[][] field) { int[][] visit = new int[field.length][field[0].length]; for(int i=0;i=0) continue; visit[i][j] = 0; if(bfs(field, visit, j, i)){ System.out.println("possible"); return; } } } System.out.println("impossible"); } int[] dx = {-1, 0, 1, 0}; int[] dy = {0, 1, 0, -1}; private boolean bfs(int[][] field, int[][] visit, int cx, int cy){ LinkedList q = new LinkedList(); LinkedList from = new LinkedList(); q.offer(new Point(cx, cy)); from.offer(new Point(cx, cy)); while(!q.isEmpty()){ Point p = q.poll(); Point f = from.poll(); for(int i=0;i<4;i++){ int nx = p.x + dx[i]; int ny = p.y + dy[i]; if(field[p.y][p.x]!=field[ny][nx]) continue; if(visit[ny][nx]>0 && (nx!=f.x || ny!=f.y)){ return true; }else if(visit[ny][nx]<0){ q.offer(new Point(nx, ny)); from.offer(new Point(p.x, p.y)); visit[ny][nx] = visit[p.y][p.x]+1; } } } return false; } private class Point{ public int x; public int y; public Point(int x, int y) { this.x = x; this.y = y; } } }