#include <iostream>
#include <cstring>
#include <stack>
#define maxn 1000
using namespace std;
stack <int> s;
char g[maxn][maxn];
bool used[maxn][maxn];
int n,m, max_d=0, root_x=0, root_y=0;
void dfs(int cx,int cy, int h){
    s.push(cx);
    s.push(cy);
    s.push(h);
    while(!s.empty()){
        int h=s.top();
        s.pop();
        int y=s.top();
        s.pop();
        int x=s.top();
        s.pop();
        used[x][y]=true;
    if(h>max_d)
        max_d=h,root_x=x,root_y=y;
    if(x>0 && g[x-1][y]=='.' && !used[x-1][y])
        s.push(x-1),s.push(y),s.push(h+1);
    if(y>0 && g[x][y-1]=='.' && !used[x][y-1])
        s.push(x),s.push(y-1),s.push(h+1);
    if(x<n-1 && g[x+1][y]=='.' && !used[x+1][y])
        s.push(x+1),s.push(y),s.push(h+1);
    if(y<m-1 && g[x][y+1]=='.' && !used[x][y+1])
       s.push(x),s.push(y+1),s.push(h+1);
    }
}
int main(){
    cin>>m>>n;
    for(int i=0; i<n; ++i){
        cin>>g[i];
        for(int j=0; j<m; ++j)
             used[i][j]=false;
    }
    for(int i=0; i<n; ++i){
        for(int j=0; j<m; ++j)
            if(g[i][j]=='.' && !used[i][j]){
                dfs(i,j,0);
                for(int k=0;k<n;++k)
                    for(int l=0;l<m;++l)
                        used[k][l]=0;
                dfs(root_x,root_y,0);
        }
    }
    cout<<max_d<<endl;
    return 0;
}