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.stream.*;
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        char[][] s = IntStream.range(0, h).mapToObj(i -> scanner.next().toCharArray()).toArray(char[][]::new);
        int[][] dist = new int[h][w];
        Arrays.stream(dist).forEach(array -> Arrays.fill(array, 10000));
        dist[0][0] = 0;
        Deque<Integer> deque = new ArrayDeque<>();
        deque.add(0);
        while (!deque.isEmpty()) {
            int i = deque.poll();
            int x = i % w;
            int y = i / w;

            if (y > 0 && dist[y - 1][x] > dist[y][x] + 1 && s[y - 1][x] == '.') {
                dist[y - 1][x] = dist[y][x] + 1;
                deque.addFirst(i - w);
            }
            if (y < h - 1 && dist[y + 1][x] > dist[y][x] + 1 && s[y + 1][x] == '.') {
                dist[y + 1][x] = dist[y][x] + 1;
                deque.addFirst(i + w);
            }
            if (x > 0 && dist[y][x - 1] > dist[y][x] + 1 && s[y][x - 1] == '.') {
                dist[y][x - 1] = dist[y][x] + 1;
                deque.addFirst(i - 1);
            }
            if (x < w - 1 && dist[y][x + 1] > dist[y][x] + 1 && s[y][x + 1] == '.') {
                dist[y][x + 1] = dist[y][x] + 1;
                deque.addFirst(i + 1);
            }
        }

        if (dist[h - 1][w - 1] == 10000) {
            System.out.println(-1);
        } else {
            int ans = -dist[h - 1][w - 1] - 1;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (s[i][j] == '.') {
                        ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }
}