program probD
  implicit none
  integer H,W,i,j,k,black
  integer tmp_mat(0:60,0:60)
  integer,allocatable :: s(:,:)
  character(50) ::tmp

  read(*,*) H,W
  allocate(s(0:H+1,0:W+1))

  black=0
  s=-1
  tmp_mat=0
  tmp_mat(0,:)=-1;tmp_mat(:,0)=-1
  tmp_mat(H+1,:)=-1;tmp_mat(:,W+1)=-1
  tmp_mat(1,1)=1
  
  do i=1,H
     read(*,*) tmp
     do j=1,W
        if(tmp(j:j)=='.') then
           s(i,j)=0
        end if
        if(tmp(j:j)=='#') then
           s(i,j)=1
           tmp_mat(i,j)=-1
           black=black+1
        end if
     end do
  end do


  k=0

  do while(k<H*W+1)
     k=k+1
     do i=1,H
        do j=1,W
           if(tmp_mat(i,j)==k)then
              if(tmp_mat(i,j+1)==0.and.s(i,j+1)==0) then
                 tmp_mat(i,j+1)=k+1
              end if
              if(tmp_mat(i,j-1)==0.and.s(i,j-1)==0) then
                 tmp_mat(i,j-1)=k+1
              end if
              if(tmp_mat(i+1,j)==0.and.s(i+1,j)==0) then
                 tmp_mat(i+1,j)=k+1
              end if
              if(tmp_mat(i-1,j)==0.and.s(i-1,j)==0) then
                 tmp_mat(i-1,j)=k+1
              end if
           end if
        end do
     end do
     if(tmp_mat(H,W)>0) exit
  end do
  

  if(tmp_mat(H,W)==0) then
     write(*,*) -1
  else
     write(*,*)H*W-tmp_mat(H,W)-black
  end if
    
end program probD
