use std::io::Read; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let w: usize = itr.next().unwrap().parse().unwrap(); let h: usize = itr.next().unwrap().parse().unwrap(); let m: Vec> = (0..h) .map(|_| { (0..w) .map(|_| itr.next().unwrap().parse().unwrap()) .collect() }) .collect(); let mut checked: Vec> = vec![vec![false; w]; h]; let mut q = std::collections::VecDeque::new(); let dx: Vec = [0, 1, 0, -1].to_vec(); let dy: Vec = [1, 0, -1, 0].to_vec(); for i in 0..h { for j in 0..w { let checking_num = m[i][j]; if checked[i][j] { continue; } q.push_back((i, j, 0, 0)); while let Some((y, x, py, px)) = q.pop_front() { checked[y][x] = true; for k in 0..4 { let nx = x as isize + dx[k]; let ny = y as isize + dy[k]; if nx == px && ny == py { continue; } if 0 <= nx && nx < w as isize && 0 <= ny && ny < h as isize && m[ny as usize][nx as usize] == checking_num { if checked[ny as usize][nx as usize] { println!("possible"); return; } q.push_back((ny as usize, nx as usize, y as isize, x as isize)); } } } } } println!("impossible"); }