Problem:
Score : 200 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).

You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is # if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is .. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Constraints

2 \leq H, W \leq 8

a_{i,j} is either # or ..

There exists a valid sequence of moves for Shik to generate the map a.

Input

The input is given from Standard Input in the following format:

H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}

Output

If it is possible that Shik only uses right and down moves, print Possible. Otherwise, print Impossible.

Sample Input 1

4 5
##...
.##..
..##.
...##

Sample Output 1

Possible

The matrix can be generated by a 7-move sequence: right, down, right, down, right, down, and right.

Sample Input 2

5 3
###
..#
###
#..
###

Sample Output 2

Impossible

Sample Input 3

4 5
##...
.###.
.###.
...##

Sample Output 3

Impossible

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        int[] hw = IO.INT(' ');
        string[] m = IO.STRING(hw[0]);
        int n = 0;
        string o = "Possible";
        for (int i = 0; i < hw[0]; i++)
        {
            bool start = false;
            for (int j = 0; j < hw[1]; j++)
            {
                if (m[i][j] == '#' && !start)
                {
                    if (j < n)
                    {
                        o = "Impossible";
                        break;
                    }
                    start = true;
                }
                if (m[i][j] == '#' && j == hw[1] - 1)
                {
                    n = j;
                }
                if (start && m[i][j] == '.')
                {
                    n = j - 1;
                    start = false;
                }
            }
            if (o == "Impossible")
            {
                break;
            }
        }
        IO.WRITE(o);
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(object s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}