//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
//#define int long long
#define endl '\n'
#define pll pair<long long,long long>
//#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            queue<pii>q;
            int dist[n][m];
            memset(dist,-1,sizeof(dist));
            dist[i][j]=0;
            q.push({i,j});
            while(!q.empty()){
                auto p=q.front();
                q.pop();
                ans=max(ans,dist[p.fi][p.se]);
                for(int i=0;i<4;i++){
                    if(p.fi+dx[i]<n&&p.fi+dx[i]>=0&&p.se+dy[i]<m&&p.se+dy[i]>=0){
                        if(dist[p.fi+dx[i]][p.se+dy[i]]==-1&&s[p.fi+dx[i]][p.se+dy[i]]=='.'){
                            dist[p.fi+dx[i]][p.se+dy[i]]=dist[p.fi][p.se]+1;
                            q.push({p.fi+dx[i],p.se+dy[i]});
                        }
                    }
                }
            }
            //cout<<i<<" "<<j<<" "<<ans<<endl;
        }
    }
    cout<<ans;
    return 0;
}