#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
char arr[21][21];
ll h,w;
ll dirx[4] = {-1,1,0,0};
ll diry[4] = {0,0,1,-1};
bool check(ll x,ll y)
{
    if(x>=h or x<0 or y>=w or y<0)
        return 0;
    return 1;
}
ll func(ll x,ll y)
{
    queue < pii > q;
    ll visited[21][21] = {0};
    ll dist[21][21];
    ll i,j;
    for(i=0;i<21;i++)
    {
        for(j=0;j<21;j++)
            dist[i][j] = -1e18;
    }
    visited[x][y] = 1;
    q.push(mp(x,y));
    dist[x][y] = 0;
    ll ans = 0;
    while(!q.empty())
    {
        pii temp = q.front();
        q.pop();
        for(i=0;i<4;i++)
        {
            ll xx = temp.fi+dirx[i];
            ll yy = temp.sec+diry[i];
            if(check(xx,yy) and !visited[xx][yy] and arr[xx][yy]=='.')
            {
                visited[xx][yy] = 1;
                dist[xx][yy] = dist[temp.fi][temp.sec]+1;
                ans = max(dist[xx][yy],ans);
                q.push(mp(xx,yy));
            }
        }
    }
    return ans;
}
signed main()
{
    fast;
    cin>>h>>w;
    ll i,j;
    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
            cin>>arr[i][j];
    ll ans = 0;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            if(arr[i][j]=='.')
            {
                ans = max(ans,func(i,j));
            }
        }
    }
    cout<<ans;
    
}


Measured memory_bytes: 256