#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 998244353
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
char ch[21][21];
ll visit[21][21],dis[21][21];
ll bfs(ll x,ll y,ll n,ll m)
{
    ll ans=0,val,val1;
    memset(visit,0,sizeof(visit));
    memset(dis,0,sizeof(dis));
    queue<pair<ll,ll>>q;
    q.push(mk(x,y));
    dis[x][y]=0;
    while(q.size()!=0)
    {
        pair<ll,ll>p=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            val=p.fi+dx[i];
            val1=p.se+dy[i];
            if(visit[val][val1]==0 && val>=0  && val<n && val1>=0 && val1<m && ch[val][val1]=='.')
            {
                visit[val][val1]=1;
                dis[val][val1]=dis[p.fi][p.se]+1;
                q.push({val,val1});
                ans=max(dis[val][val1],ans);
            }
        }
    }
    return ans;
}
int main()
{
    ll h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>ch[i][j];
        }
    }
    ll x,y,val,val1,ans=INT_MIN;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(ch[i][j]=='.')
            {
                ans=max(ans,bfs(i,j,h,w));
            }
        }
    }
    cout<<ans<<endl;
}