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 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
    
        int r = in.nextInt();
        int c = in.nextInt(); in.nextLine();
        int area = r*c;
        int[] dx = {0,-1,0,1};
        int[] dy = {-1,0,1,0};
        char[][] map = new char[r][c];
        int blackSquares = 1;
        for( int i = 0; i < r; i++ ) {
            String l = in.nextLine();
            for( int j = 0; j < c; j++ ) {
                map[i][j] = l.charAt(j);
                if(map[i][j]=='#') blackSquares++;
            }
        }

        PriorityQueue<Node> q = new PriorityQueue<>();
        int[][] distance = new int[r][c];
        for( int[] i : distance ) Arrays.fill(i,-1);
        q.add(new Node(0,0,0));
        distance[0][0] = 0;
        boolean reached = false;
        while(!q.isEmpty()) {
            Node curr = q.remove();
            if( curr.r == r-1 && curr.c == c-1 ) reached = true;
            for( int i = 0; i < 4; i++ ) {
                int x = curr.r + dx[i];
                int y = curr.c + dy[i];
                if( x < 0 || x >= r || y < 0 || y >= c ) continue;
                if( map[x][y] == '#' ) continue;
                int temp = 1+curr.distance;
                if( distance[x][y] == -1 || distance[x][y] > temp) {
                    distance[x][y] = temp;
                    q.add(new Node(x,y,distance[x][y]));
                }
            }
        }
        if( reached ) System.out.println((area-blackSquares)-distance[r-1][c-1]);
        else System.out.println(-1);
    }
    static class Node implements Comparable<Node>{
        int r,c;
        int distance;
        public Node(int r, int c, int distance) {
            this.r = r;
            this.c = c;
            this.distance = distance;
        }
        public int compareTo(Node n) {
            return distance - n.distance;
        }
    }
}