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.awt.Point;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	final static PrintStream so = System.out;
	final static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[][] s = new int[H][W];
		int dots = 0;
		
		for (int h = 0; h < H; h++) {
			String line = sc.next();
			
			for (int w = 0; w < W; w++) {
				s[h][w] = line.charAt(w) == '.' ? 0 : -1;
				if (s[h][w] == 0) dots++;
			}
		}
		
		Queue<Point> queue = new ArrayDeque<>();
	    /* Point(2, 3) -> s[3][2] (x, y -> w, h) */
		
		queue.add(new Point(0, 0));
		s[0][0] = 1;
		
		int[] mx = {0, 1, 0, -1};
		int[] my = {1, 0, -1, 0};
		
		while (!queue.isEmpty()) {
			Point current = queue.poll();
			int cx = current.x;
			int cy = current.y;
			
			for (int i = 0; i < my.length; i++) {
				int nx = cx + mx[i];
				int ny = cy + my[i];
				
				if (inRange(nx, 0, W) && inRange(ny, 0, H) && s[ny][nx] == 0) {
					s[ny][nx] = s[cy][cx] + 1;
					queue.add(new Point(nx, ny));
				}
			}
		}
		
		so.println(s[H-1][W-1] == 0 ? -1: dots-s[H-1][W-1]);
	}
	
	static boolean inRange(int x, int l, int r) {
		return l <= x && x < r;
	}
}