// Original C++ solution (slower):
#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <fstream>

#include <sstream>

#include <set>

#include <map>

#include <vector>

#include <list>

#include <algorithm>

#include <cstring>

#include <cmath>

#include <string>

#include <queue>

#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic

#include <cassert>

#include <iomanip>        //do setprecision

#include <ctime>

#include <complex>

using namespace std;



#define FOR(i,b,e) for(int i=(b);i<(e);++i)

#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)

#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)

#define REP(x, n) for(int x = 0; x < (n); ++x)



#define ST first

#define ND second

#define PB push_back

#define MP make_pair

#define LL long long

#define ULL unsigned LL

#define LD long double



const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int mod=1000000007;



int main(){

	int h,w;

	int a[55][55]={};

	int s[55][55]={};

	int di[4]={-1,0,1,0};

	int dj[4]={0,1,0,-1};



	cin>>h>>w;

	int all=0;

	FORQ(i,1,h){

		FORQ(j,1,w){

			a[i][j]=0;

			s[i][j]=mod;

		}

	}

	//s[1][1]=1;

	FORQ(i,1,h){

		FORQ(j,1,w){

			char ch;

			cin>>ch;

			if(ch=='.'){

				a[i][j]=1;

				all++;

			}

		}

	}

	//cout<<all<<endl;

	priority_queue<pair<int,pair<int,int>>> pq;

	pq.push(make_pair(1,make_pair(1,1)));

	while(!pq.empty()){

		pair<int,pair<int,int>> pr=pq.top();

		pq.pop();

		int nx=pr.ND.ST,ny=pr.ND.ND,dist=pr.ST;

		if(dist<s[nx][ny])s[nx][ny]=dist;

		else continue;

		//cout<<nx<<" "<<ny<<" "<<dist<<endl;

		FOR(i,0,4){

			int x=pr.ND.ST+di[i],y=pr.ND.ND+dj[i];

			if(a[x][y]){

				pq.push(make_pair(pr.ST+1,make_pair(x,y)));

			}

		}

	}

	if(s[h][w]==mod){

		cout<<-1<<endl;

	}else cout<<all-s[h][w]<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <fstream>

#include <sstream>

#include <set>

#include <map>

#include <vector>

#include <list>

#include <algorithm>

#include <cstring>

#include <cmath>

#include <string>

#include <queue>

#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic

#include <cassert>

#include <iomanip>        //do setprecision

#include <ctime>

#include <complex>

using namespace std;



#define FOR(i,b,e) for(int i=(b);i<(e);++i)

#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)

#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)

#define REP(x, n) for(int x = 0; x < (n); ++x)



#define ST first

#define ND second

#define PB push_back

#define MP make_pair

#define LL long long

#define ULL unsigned LL

#define LD long double



const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int mod=1000000007;



int main(){

	int h,w;

	int a[55][55]={};

	int s[55][55]={};

	int di[4]={-1,0,1,0};

	int dj[4]={0,1,0,-1};



	cin>>h>>w;

	int all=0;

	FORQ(i,1,h){

		FORQ(j,1,w){

			a[i][j]=0;

			s[i][j]=mod;

		}

	}

	//s[1][1]=1;

	FORQ(i,1,h){

		FORQ(j,1,w){

			char ch;

			cin>>ch;

			if(ch=='.'){

				a[i][j]=1;

				all++;

			}

		}

	}

	//cout<<all<<endl;

	priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int>>>> pq;

	pq.push(make_pair(1,make_pair(1,1)));

	while(!pq.empty()){

		pair<int,pair<int,int>> pr=pq.top();

		pq.pop();

		int nx=pr.ND.ST,ny=pr.ND.ND,dist=pr.ST;

		if(dist<s[nx][ny])s[nx][ny]=dist;

		else continue;

		if(nx==h&&ny==w)break;

		//cout<<nx<<" "<<ny<<" "<<dist<<endl;

		FOR(i,0,4){

			int x=pr.ND.ST+di[i],y=pr.ND.ND+dj[i];

			if(a[x][y]){

				pq.push(make_pair(pr.ST+1,make_pair(x,y)));

			}

		}

	}

	if(s[h][w]==mod){

		cout<<-1<<endl;

	}else cout<<all-s[h][w]<<endl;

    return 0;

}


// Fastest known solution for this problem: