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.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りではない別回答
 */
public class Main {

	/** 白のコマ */
	private static final char WHITE = '.';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			boolean[][] s = new boolean[h][w];
			IntStream.range(0, h).forEach(i -> Arrays.fill(s[i], false));
			int whiteCount = 0;
			for (int i = 0; i < h; i++) {
				char[] l = scanner.next().toCharArray();
				for (int j = 0; j < w; j++) {
					s[i][j] = (l[j] == WHITE);
					if (s[i][j]) {
						whiteCount++;
					}
				}
			}
			int[][] v = new int[h][w];
			IntStream.range(0, h).forEach(i -> Arrays.fill(v[i], Integer.MAX_VALUE));
			v[0][0] = 1;
			calcResult(0, 0, s, v);
			System.out.println((v[h - 1][w - 1] < Integer.MAX_VALUE) ? whiteCount - v[h - 1][w - 1] : -1);
		}
	}

	/**
	 * @param x X座標
	 * @param y Y座標
	 * @param s マスの状態の配列
	 * @param v (0,0)からそれぞれのマスへ移動する場合の通過マスの数の最小値
	 */
	private static void calcResult(int x, int y, final boolean[][] s, final int[][] v) {
		int h = s.length, w = s[0].length;
		if (((h - 1) == x) && ((w - 1) == y)) {
			// 終点の場合、終了
			return;
		}
		if ((x > 0) && s[x - 1][y] && (v[x][y] + 1 < v[x - 1][y])) {
			v[x - 1][y] = v[x][y] + 1;
			calcResult(x - 1, y, s, v);
		}
		if ((y > 0) && s[x][y - 1] && (v[x][y] + 1 < v[x][y - 1])) {
			v[x][y - 1] = v[x][y] + 1;
			calcResult(x, y - 1, s, v);
		}
		if ((x < h - 1) && s[x + 1][y] && (v[x][y] + 1 < v[x + 1][y])) {
			v[x + 1][y] = v[x][y] + 1;
			calcResult(x + 1, y, s, v);
		}
		if ((y < w - 1) && s[x][y + 1] && (v[x][y] + 1 < v[x][y + 1])) {
			v[x][y + 1] = v[x][y] + 1;
			calcResult(x, y + 1, s, v);
		}
	}
}