// --------------
// Tejas Pandey  |
// 12 - 01 - 20  |
// ABC #151      |
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

ll solve(char a[20][20],int h,int w,int x,int y){
	int vis[20][20];
	memset(vis,0,sizeof(vis));
	queue<tuple<int,int,ll>> pt;
	pt.push(make_tuple(x,y,0));
	ll ans = 0;
	while(!pt.empty()){
		tuple<int,int,int> t = pt.front();
		pt.pop();
		pair<int,int> p = make_pair(get<0>(t),get<1>(t));
		if(!vis[p.first][p.second] && a[p.first][p.second] == '.'){
			ll f =get<2>(t);
			ans = max(ans,f);
			vis[p.first][p.second] = 1;
			if(p.first + 1 < h){
				pt.push(make_pair(p.first+1,p.second,get<2>(t) + 1));
			}
			if(p.first - 1 > -1){
				pt.push(make_pair(p.first-1,p.second,get<2>(t) + 1));
			}
			if(p.second + 1 < w){
				pt.push(make_pair(p.first,p.second+1,get<2>(t) + 1));
			}
			if(p.second - 1 > -1){
				pt.push(make_pair(p.first,p.second-1,get<2>(t) + 1));
			}
		}
	}
	return ans;
}

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		int h,w;
		cin >> h >> w;
		char a[20][20];
		for(int i = 0;i < h;i++)
			for(int j = 0;j < w;j++)
				cin >> a[i][j];
		ll ans = 0;
		for(int i = 0;i < h;i++)
			for(int j = 0;j < h;j++)
				if(a[i][j] == '.')
					ans = max(ans,solve(a,h,w,i,j));
		cout << ans << "\n";
	}
	return 0;
}