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 static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        long[] HW = LongLine();
        long H = HW[0], W = HW[1];
        long s = 0;
        for (int i = 0; i < H; i++)
        {
            s += Console.ReadLine().Count(c => c == '#');
        }
        if(s == H+W-1) Console.WriteLine("Possible");
        else Console.WriteLine("Impossible");

    }
}

public class Factorization
{
    private static long N;

    public Factorization(long n) { N = n; }

    //最大公約数を返す
    public static long GCD(long a, long b)
    {
        if (a < b) return GCD(b, a);
        long r;
        while (b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    //素数判定
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        double root = Math.Sqrt(n);
        for (int i = 3; i <= root; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

    //試し割り
    private static int[] TryPrimes = new int[] { 2, 3, 5, 7, 11 };
    public long TryAllocation(long p)
    {
        long count = 0;
        while (N % p == 0)
        {
            count++;
            N /= p;
        }
        return count;
    }

    private int[] xi = new int[] { 13, 17, 19, 23, 29 };
    private long f(long x, int suffix)
    {
        return (xi[suffix % xi.Count()] * x + suffix) % N;
    }

    //nを分解
    public long PollardsRho(long n, int suffix = 0)
    {
        //素数を渡すと失敗するらしい
        if (IsPrime(n)) return n; //もう素数
        long x = 2, y = 2, d = 1;
        while (d == 1)
        {
            x = f(x, suffix);
            y = f(f(y, suffix), suffix);
            d = GCD(Math.Abs(x - y), n);
        }
        if (d == n)
        {
            //f(x)を変えて試す
            return PollardsRho(n, suffix + 1);
        }
        return d;
    }

    public IEnumerable<long> Calc()
    {
        //小さな素因数の計算
        foreach (var prime in TryPrimes)
        {
            var box = TryAllocation(prime);
            for (int i = 0; i < box; i++) yield return prime;
        }

        //残りをRhoで解く
        while (true)
        {
            if (N == 1) break;
            var ret = PollardsRho(N);
            yield return ret;
            N /= ret;
        }
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static long[] LSRead()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static long Combination(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r + 1), r).ToList().Aggregate((now, next) => now * next) /
            Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next);
    }
    public static long Permutation(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r), r).ToList().Aggregate((now, next) => now * next);
    }
    public static long LongRead()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] LongLine()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
}