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 System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        static List<List<int>> G = new List<List<int>>();
        //static List<List<Edge>>G = new List<List<Edge>>();
        //static List<Edge> E = new List<Edge>();

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            var input = cin.ReadSplit();
            int H = input[0];
            int W = input[1];
            var map = new char[H + 1][];
            for(var i = 0; i <= H; i++)
            {
                map[i] = new char[W + 1];
                if (i == H)
                {
                    for (var j = 0; j <= W; j++) map[i][j] = '.';
                }
                else
                {
                    var p = Console.ReadLine();
                    for(var j = 0; j <= W; j++)
                    {
                        map[i][j] = j == W ? '.' : p[j];
                    }
                }
            }
            var ch = new bool[H + 1][];
            for(var i = 0; i <= H; i++)
            {
                ch[i] = new bool[W + 1];
                Initialize(ref ch[i], false);
            }
            Func<int, int, int> dfs = null;
            dfs = (i, j) =>
            {
                ch[i][j] = true;
                if (map[i + 1][j] == '#' && !ch[i + 1][j]) { dfs(i + 1, j); }
                else if (map[i][j + 1] == '#' && !ch[i][j + 1]) { dfs(i, j + 1); }
                return 0;
            };
            dfs(0, 0);
            for(var i = 0; i < H; i++)
            {
                for(var j = 0; j < W; j++)
                {
                    if (map[i][j] == '#'&&!ch[i][j]) { Console.WriteLine("Impossible");return; }
                }
            }
            Console.WriteLine("Possible");

            //Console.Out.Flush();
        }
        struct Edge
        {
            public int from;

            public int to;
            public long dist;
            public Edge(int t, long c)
            {
                from = -1;
                to = t;
                dist = c;
            }
            public Edge(int f, int t, long c)
            {
                from = f;
                to = t;
                dist = c;
            }

        }
    }
    public class Scanner
    {
        public int[] ReadSplit()
        {
            return ConvertAll(Console.ReadLine().Split(), int.Parse);
        }
        public long[] ReadSplitL()
        {
            return ConvertAll(Console.ReadLine().Split(), long.Parse);
        }
        public double[] ReadSplitD()
        {
            return ConvertAll(Console.ReadLine().Split(), double.Parse);
        }
    }
    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public void Swap<T>(ref T a, ref T b)
        {
            T keep = a;
            a = b;
            b = keep;
        }

        static public void Display<T>(T[,] array2d, int n, int m)
        {
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < m; j++)
                {
                    Console.Write($"{array2d[i, j]} ");
                }
                Console.WriteLine();
            }
        }

        static long LPow(int a, int b)
        {
            return (long)Pow(a, b);
        }
    }
}