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;
int main(){
	int h,w; cin >> h >> w;
	char grid[50][50];
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++) cin >> grid[i][j];
	int minmass[50][50];
	int blacknum=0;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++) {
		minmass[i][j]=(grid[i][j]=='.'?1e5:-1);
		if(grid[i][j]=='#') blacknum++;
	}
	minmass[0][0]=1;
	queue<pair<int,int>> q;
	q.push(make_pair(0,0));
	while(!q.empty()){
		int i=q.front().first;
		int j=q.front().second;
		q.pop();
		int x=1,y=0;
		for(int k=0;k<4;k++){
			if(0<=i+y&&i+y<h && 0<=j+x&&j+x<w){
				if(minmass[i+y][j+x]!=-1){
					if(minmass[i+y][j+x]>minmass[i][j]+1){
						minmass[i+y][j+x]=minmass[i][j]+1;
						q.push(make_pair(i+y,j+x));
					}
				}
			}
			int temp=x;
			x=y;
			y=-temp;
		}
	}
	int ans=h*w-minmass[h-1][w-1]-blacknum;
	if(minmass[h-1][w-1]==1e5) cout << -1 << endl;
	else cout << ans << endl;
}