#include<bits/stdc++.h>
using namespace std;
const int N=30;
int n,m,t,dis[N][N],dx[4]={-1,0,0,1},dy[4]={0,1,-1,0},ans;char c[N][N];
queue<pair<int,int> >q;
bool can(int x,int y){return x>=1&&x<=n&&y>=1&&y<=m&&c[x][y]!='#';}
void bfs(int sx,int sy){
    memset(dis,0,sizeof(dis));
    q.push(make_pair(sx,sy));dis[sx][sy]=1;
    while(q.size()){
        int x=q.front().first,y=q.front().second;q.pop();
        for(int i=0;i<4;i++){
            int xx=x+dx[i],yy=y+dy[i];
            if(can(xx,yy)&&!dis[xx][yy]){
                ans=max(ans,dis[x][y]);
                dis[xx][yy]=dis[x][y]+1,q.push(make_pair(xx,yy));
            }
        }
    }
}
int main(){
    // freopen("test.in","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%s",c[i]+1);
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(c[i][j]!='#')bfs(i,j);
    printf("%d\n",ans);
    return 0;
}