#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from collections import deque;h,w=map(int,input().split());m=[input()for _ in[0]*h];v=[[-1]*w for _ in[0]*h];q=deque([[0,0]]);v[0][0]=0;c=sum(t.count('#')for t in m)\n"
"while q:\n"
" y,x=q.popleft()\n"
" for i,j in([1,0],[-1,0],[0,1],[0,-1]):\n"
"  t,u=y+i,x+j\n"
"  if t+1and t<h and u+1and u<w and m[t][u]=='.'and v[t][u]<0:v[t][u]=v[y][x]+1;q.append([t,u])\n"
"print(-1*(v[h-1][w-1]<0)or h*w-c-v[h-1][w-1]-1)\n"
"\"";
  system(s);
  return 0;
}            