Problem: Constraints

* H is an integer between 2 and 50 (inclusive).
* W is an integer between 2 and 50 (inclusive).
* s_{i, j} is `.` or `#` (1 \leq i \leq H, 1 \leq j \leq W).
* s_{1, 1} and s_{H, W} are `.`.

Input

Input is given from Standard Input in the following format:


H W
s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W}
s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W}
:   :
s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}


Output

Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed.

Examples

Input

3 3
..#
#..
...


Output

2


Input

3 3
..#
..
...


Output

2


Input

10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................


Output

209

Solution (in JAVA):

Solution:
import java.util.*;

public class Main{
    static double[][] D;
    static String[] S;
    static int H,W;
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        H = sc.nextInt();
        W = sc.nextInt();
        S = new String[H];
        
        D = new double[H][W];
        for(int i = 0; i < H; i++){
            S[i] = sc.next();
        }
        sc.close();

        int count = 0;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(S[i].charAt(j) == '#')
                    count++;
            }
        }
       
        for(int i = 0; i < H; i++){
           Arrays.fill(D[i], Double.POSITIVE_INFINITY);
        }
        D[0][0] = 0;

        dps(0, 0);

        /*for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                System.out.print(D[i][j] + " ");
            }
            System.out.println();
        }*/
        if(D[H-1][W-1] != Double.POSITIVE_INFINITY)
            System.out.println(H*W-(int)D[H-1][W-1]-count-1);
        else
            System.out.println(-1);
    }

    static void dps(int i, int j){
            if(i+1<H && S[i+1].charAt(j) == '.' ){
                if(D[i][j]+1 >= D[i+1][j]){}
                else {
                    D[i+1][j] = D[i][j]+1;
                    dps(i+1, j);
                }
            }
            if(i-1>=0 && S[i-1].charAt(j) == '.' ){
                if(D[i][j]+1 >= D[i-1][j]){}
                else {
                    D[i-1][j] = D[i][j]+1;
                    dps(i-1, j);
                }
            }
            if(j+1<W && S[i].charAt(j+1) == '.'){
                if(D[i][j]+1 >= D[i][j+1]){}
                else {
                    D[i][j+1] = D[i][j]+1;
                    dps(i, j+1);
                }
            }
            if(j-1>=0 && S[i].charAt(j-1) == '.'){
                if(D[i][j]+1 >= D[i][j-1]){}
                else {
                    D[i][j-1] = D[i][j]+1;
                    dps(i, j-1);
                }
            }

    }
}