#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n,m;
    ll ma=0,x,y;
    cin>>n>>m;
    vector<vector<bool>> v(n,vector<bool>(m,false));
    vector<vector<bool>> u(n,vector<bool>(m,false));
    vector<vector<bool>> u2(n,vector<bool>(m,false));
    rep(i,n){
        string c;cin>>c;
        rep(j,m)if(c[j]=='.')v[i][j]=true;
    }
    rep(i,n){
        rep(j,m){
    queue<PP> q;
        q.push(PP(i,j,0));
        while(!q.empty()){
        auto p=q.front();q.pop();
        ll i=get<0>(p),j=get<1>(p),d=get<2>(p);
        u[i][j]=true;
        chmax(ma,d);
        if(i+1<n)if(!u[i+1][j]&&v[i+1][j]){
            u[i+1][j]=true;
            q.push(PP(i+1,j,d+1));
        }
        if(i-1>=0)if(!u[i-1][j]&&v[i-1][j]){
            u[i-1][j]=true;
            q.push(PP(i-1,j,d+1));
        }
        if(j+1<m)if(!u[i][j+1]&&v[i][j+1]){
            u[i][j+1]=true;
            q.push(PP(i,j+1,d+1));
        }
        if(j-1>=0)if(!u[i][j-1]&&v[i][j-1]){
            u[i][j-1]=true;
            q.push(PP(i,j-1,d+1));
        }
    }
        }
    out(ma);
}