#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7 ;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
 
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}

int n,m;
ll cal(vector<string> &arr,int x,int y)
{
    vp64 frontier;
    vv64 dist(21,v64(21,-1));
    frontier.push_back(p64(x,y));
    ll ans=0;
    dist[x][y]=0;
    while (frontier.size()>0)
    {
        vp64 next;
        for (int i=0; i<sz(frontier); i++)
        {
            int a=frontier[i].fi;
            int b=frontier[i].se;
            // cout <<a<< " "<<b<<" "<<dist[a][b]<<endl;
            ans=max(ans,dist[a][b]);
            if (a>1 && dist[a-1][b]==-1 && arr[a-1][b]=='.')
            {
                next.push_back(p64(a-1,b));
                dist[a-1][b]=dist[a][b]+1;
            }
            if (b>1 && dist[a][b-1]==-1  && arr[a][b-1]=='.')
            {
                next.push_back(p64(a,b-1));
                dist[a][b-1]=dist[a][b]+1;
            }
            if (a<n && dist[a+1][b]==-1  && arr[a+1][b]=='.')
            {
                next.push_back(p64(a+1,b));
                dist[a+1][b]=dist[a][b]+1;
            }
            if (b<m && dist[a][b+1]==-1  && arr[a][b+1]=='.')
            {
                next.push_back(p64(a,b+1));
                dist[a][b+1]=dist[a][b]+1;
            }
        }
        frontier=next;
    }
    return ans;
}
void solve()
{
    cin>>n>>m;
    vector<string> arr(n+1);
    for (int i=1; i<=n; i++)
    {
        cin>>arr[i];
        arr[i]="a"+arr[i];
    }

    ll ans=0;
    // cout <<cal(arr,1,3)<<endl;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=m; j++)
        {
            if (arr[i][j]=='.')
            ans=max(ans,cal(arr,i,j));
            // cout << i <<" "<<j <<" "<<cal(arr,i,j)<<endl;
        }
    }
    cout << ans<<endl;
}
 
int main() {
    fast_cin();
    int t=1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256