/*

A try towards peace

*/

#include <bits/stdc++.h>
using namespace std;
#define yo long long int
#define lo mp::cpp_int
#define pb push_back
#define pob pop_back
#define mp make_pair
#define endl "\n"
#define ce(x) cout << x <<"\n"
#define fill(s,v) memset(s,v,sizeof(s))
#define speed  { ios_base::sync_with_stdio(false); cin.tie(0); }
#define for2(i,a,b) for(yo i=a;i<b;i++)
#define for3(i,a,b) for(yo i=a;i<=b;i++)
#define for1(a,b) for(yo i=a;i<b;i++)
#define deb(x) cout<<#x<<" "<<x<<endl; 
#define INFINITE 1000000009
#define ull unsigned long long int
#define take(a,n) for(yo pp=0;pp<n;pp++) { cin>>a[pp]; }
#define take2(a,n) for(yo p=0;p<n;p++) { yo temp;cin>>temp;a.pb(temp); }
#define show(a,n) for(yo p=0;p<n;p++) cout<<a[p]<<" ";
#define _ <<" "<<
#define nl cout<<endl;
#define sq(x) ((x)*(x))
#define call(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ff first
#define ss second
#define lld long double
#define pii pair<yo,yo>
#define tc(tt) \
    yo tt;    \
    cin >> tt; \
    for (int _tt = 0; _tt < tt; _tt++) 
 
const yo dx[4] = {-1, 0, 1, 0};
const yo dy[4] = {0, -1, 0, 1};
const yo N = 1000*1000+5;
const yo size = 1000*100*2+5;
const yo mod = 1000*1000*1000+7;
 
yo gcd(yo a, yo b){if(!b)return a;return gcd(b, a % b);} 
yo power_mod(yo x,yo y,yo p){yo res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
yo lcm(yo a, yo b){return (a*b)/gcd(a, b);}
yo sumofdigits(yo n){yo out=0;while(n){out+=(n%10);n/=10;}return out;}
bool isPrime(yo n){if (n <= 1)  return false; if (n <= 3)  return true; if (n%2 == 0 || n%3 == 0) return false; for (yo i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;return true;} 
yo power(yo a,yo b){if(b==0)return 1;if(b&1)return a*power(a,b-1);yo res=power(a,b/2);return res*res;}
yo log(yo d){return log2(d);}
bool isPower(yo x, yo y){if(x==1) return (y==1); yo pow=1; while(pow<y) pow*=x; return(pow == y);}  
bool compare (const pair<yo,yo> &i,const pair<yo,yo> &j){return i.first < j.first;}
yo i,j;

lld polygonArea(lld X[], lld Y[], yo n) 
{   
    lld area = 0.0; 
    yo j = n - 1; 
    for (yo i = 0; i < n; i++) 
    { 
        area += (X[j] + X[i]) * (Y[j] - Y[i]); 
        j = i;  
    }    
    return abs(area); 
} 
// bool prime[100200];
// vector<yo> dp;
 
// void SieveOfEratosthenes(yo n) 
// {   
//     for (yo p=2; p*p<=n; p++) 
//     { 
//         if (prime[p] == true) 
//         { 
//             for ( i=p*p; i<=n; i += p) 
//                 prime[i] = false;   
//         } 
//     } 
  
//     for (yo p=2; p<=n; p++)  
//        if (prime[p]) 
//           dp.pb(p); 
// } 

int main ()
{
        yo n,m,ans=-1e9; cin>>n>>m;
        vector <string> v(n);
        for1(0,n)
        {
            cin>>v[i];
        }
        vector<pii> point;
        for1(0,n)
        {
            for2(j,0,m)
            {
                if(v[i][j]=='.')
                {
                    point.pb({i,j});
                }
            }
        }

        queue<pii> q;
        bool visited[n+1][m+1];
        yo dis[n+1][m+1];

        for(auto &pt:point)
        {   
            fill(visited,false);
            fill(dis,0);
            yo xx=pt.ff;
            yo yy=pt.ss;
            q.push({xx,yy});
            visited[xx][yy]=true;
            dis[xx][yy]=0;
            yo maxi=0;

            while(!q.empty())
            {
                pii now=q.front();
                yo x=now.ff;    
                yo y=now.ss;
                q.pop();
                for(i=0;i<4;i++)
                {
                    yo newx=x+dx[i];
                    yo newy=y+dy[i];
                    if((newx>=0 and newx<n) && (newy>=0 and newy<m) && visited[newx][newy]==false && v[newx][newy]=='.')
                    {
                        q.push({newx,newy});
                        visited[newx][newy]=true;
                        dis[newx][newy]=dis[x][y]+1;
                        maxi=max(maxi,dis[newx][newy]);
                    }
                }
            }
            ans=max(ans,maxi);

        }

        ce(ans);

}
/*


3
6 9
1 1
1 2



*/

Measured memory_bytes: 256