#include <fstream>
#include <iostream>
#include <queue>

#define nMax 101
#define mMax 101
#define mkp make_pair
#define x first
#define y second

using namespace std;

const int dx[]={1, 0};
const int dy[]={0, 1};
int n, m, mat[nMax][mMax], Sol;
char sir[nMax];
queue<pair<int, int> > Q;

int main()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        cin>>sir+1;
        for(int j=1; j<=m; j++)
            mat[i][j]=(sir[j]=='.' ? 0 : 1);
    }

    if(mat[1][1]==0)
    {
        Q.push(mkp(1, 1));
        mat[1][1]=1;
    }

    while(!Q.empty())
    {
        int x=Q.front().x, y=Q.front().y;
        Q.pop();
        Sol=max(Sol, mat[x][y]);
        for(int i=0; i<2; i++)
        {
            int l=x+dx[i];
            int c=y+dy[i];
            if(mat[l][c]==0 && l<=n && c<=m)
            {
                mat[l][c]=mat[x][y]+1;
                Q.push(mkp(l, c));
            }
        }
    }

    cout<<Sol;

}