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<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define irep(i,a)for(int i=1;i<=a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
char t[1000][1000];
int dp[1000][1000];

int h,w;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void dfs(int y,int x){
	//cout<<y<<" "<<x<<endl;

	rep(i,4){
		int ny=y+dy[i];
		int nx=x+dx[i];
		if(ny>=1&&nx>=1&&nx<=w&&ny<=h&&t[y][x]=='.'){

			if(dp[ny][nx]>dp[y][x]+1||dp[ny][nx]==0){
				dp[ny][nx]=dp[y][x]+1;
				dfs(ny,nx);
			
			}
		}
	}

}
int main(){
cin>>h>>w;
int cnt=0;
for(int i=1;i<=h;i++){
	for(int j=1;j<=w;j++){
	cin>>t[i][j];
		if(t[i][j]=='.')cnt++;
	}
}

dp[1][1]=1;


dfs(1,1);
if(dp[h][w]==0)cout<<-1<<endl;
else cout<<cnt-dp[h][w]<<endl;

	return 0;
}