#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second
 
/*
//functions from gfg
 
long long int power(long long int x,long long int y,long long  int p)
{
    long long int res = 1;     // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            {//d=(long double)x/p;
            res = (res*x) % p;
            }
 
        // y must be even now
        y = y>>1; // y = y/2
        x=(x*x)%p;
        
    }
    return res%p;
}
 
long long int gcd(long long int a,long long int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
 
long long int binomialCoeff(long long int n, ll k) 
{ 
    ll res = 1; 
  
    // Since C(n, k) = C(n, n-k) 
    if (k > n - k) 
        k = n - k; 
  
    // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1] 
    for (ll i = 0; i < k; ++i) 
    { 
        res *= (n - i); 
        res /= (i + 1); 
    } 
  
    return res; 
} 
 

void sieve(int n, vector<ll> &primes) 
{ 
    vector<int> prime(n,1);
    ll p;
    for ( p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == 1) 
        { 
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 0; 
        } 
    } 
  
    for(p=2;p<=n;p++)
    {
        if(prime[p])
        primes.pb(p);
    }
   
} 


void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
    vis[src]=1;
    for(ll i=0;i<adj[src].size();i++)
    {
        if(vis[adj[src][i]]==0)
        dfs(adj,adj[src][i],vis)
    }
}
 
*/
ll val,n,m;
string a[20];
void bfs(ll i, ll j)
{
    queue<pair< pair<ll,ll> ,ll> > q;
    q.push({{i,j},0});
    
    vector<ll> tmp(m,0);
    vector<vector<ll> > vis(n,tmp);
    vis[i][j]=1;
    while(!q.empty())
    {
        pair< pair<ll,ll> ,ll> tmp = q.front();
        q.pop();
        i=tmp.F.F;
        j=tmp.F.S;
        val=max(val,tmp.S);
        
        if(i!=0)
        {
            if(a[i-1][j]=='.' && vis[i-1][j]==0)
            {
                q.push({{i-1,j},tmp.S+1});
                vis[i-1][j]=1;
            }
        }
        if(i!=n-1)
        {
            if(a[i+1][j]=='.' && vis[i+1][j]==0)
            {
                q.push({{i+1,j},tmp.S+1});
                vis[i+1][j]=1;
            }
        }
        if(j!=0)
        {
            if(a[i][j-1]=='.' && vis[i][j-1]==0)
            {
                q.push({{i,j-1},tmp.S+1});
                vis[i][j-1]=1;
            }
        }
        if(j!=m-1)
        {
            if(a[i][j+1]=='.' && vis[i][j+1]==0)
            {
                q.push({{i,j+1},tmp.S+1});
                vis[i][j+1]=1;
            }
        }
    }
}
int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    
    
	ll i,j,p,k,ans=0;
    cin>>n>>m;
    // string a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            
            if(a[i][j]=='#')
            continue;
            val=0;
            bfs(i,j);
            ans=max(ans,val);
        }
    }
    
    cout<<ans<<endl;
    
    
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    
	return 0;
}

Measured memory_bytes: 3664