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 CPP):

Solution:
#include <iostream>
#include <queue>
using namespace std;

struct node
{
	int x, y, w;

	node() = default;

	node(int x, int y, int w)
		: x(x), y(y), w(w)
	{
	}
};

int u[4][2]= {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int n, m, cnt;
bool g[50][50], v[50][50];
queue<node> q;

int main()
{
	int i, j, x, y;
	node k;
	char ch;
	cin >> n >> m;

	for (i=0; i<n; ++i)
		for (j=0; j<m; ++j)
		{
			cin >> ch;
			if ((g[i][j]=ch=='.')) ++cnt;
		}

	q.push(node(0, 0, 0));
	v[0][0]=true;

	while (!q.empty())
	{
		k=q.front();
		q.pop();
		if (k.x==n-1&&k.y==m-1) break;

		for (i=0; i<4; ++i)
		{
			x=k.x+u[i][0];
			y=k.y+u[i][1];

			if (x>=0&&x<n&&y>=0&&y<m&&g[x][y]&&!v[x][y])
			{
				q.push(node(x, y, k.w+1));
				v[x][y]=true;
			}
		}
	}

	if (k.x==n-1&&k.y==m-1)
		cout << cnt-k.w-1 << endl;
	else
		cout << "-1" << endl;

	return 0;
}