Scanf.scanf "%d %d" (fun h w ->
    let a = Array.init h (fun _ -> Scanf.scanf " %s" (fun s -> s)) in 

    let rec loop x y f =
        let xf = x < w - 1 && a.(y).[x + 1] = '#' in
        let yf = y < h - 1 && a.(y + 1).[x] = '#' in
        let zf = x > 0     && a.(y).[x - 1] = '#' in
        let wf = y > 0     && a.(y - 1).[x] = '#' in
        if xf && yf then false else
            if f = 0 && wf then false else
            if f = 1 && zf then false else
            if xf then loop (x + 1) y 0 else
            if yf then loop x (y + 1) 1 else
            if x = w - 1 && y = h - 1 then true else
                false

    in
    print_endline @@ if loop 0 0 3 then "Possible" else "Impossible"
)