#include <iostream>

using namespace std;

int main()
{
    int n,m,a[100][100],cx[100],cy[100];
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            {
                char x;
                cin>>x;
                if(x=='.')
                    a[i][j]=0;
                else a[i][j]=-1;
            }
    cx[0]=cy[0]=1;
    int p,u;
    p=u=0;
    if(a[1][1]==1) {
        cout<<0<<endl;
        return 0;
    }
    a[1][1]=1;
    
    while(p<=u){
        if(cx[p]+1<=m && (a[cy[p]][cx[p]+1]==0 || a[cy[p]][cx[p]+1]>=a[cy[p]][cx[p]]+1) ){
            u++;
            cx[u]=cx[p]+1;
            cy[u]=cy[p];
            a[cy[u]][cx[u]]=a[cy[p]][cx[p]]+1;
        }
        if(cy[p]+1<=n && (a[cy[p]+1][cx[p]]==0 || a[cy[p]+1][cx[p]]>=a[cy[p]][cx[p]]+1) ){
            u++;
            cx[u]=cx[p];
            cy[u]=cy[p]+1;
            a[cy[u]][cx[u]]=a[cy[p]][cx[p]]+1;
        }
        p++;
    }
    int ma=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
           if(a[i][j]>ma)
           ma=a[i][j];
    cout<<ma<<endl<<flush;}