//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
using namespace std;
const int size=21;
const int inf=1e9;
int h,w;
string grid[size];

int r[]={0,0,1,-1};
int c[]={1,-1,0,0};

int dijkstra(int x1,int y1){
	vector<vector<int> > dist(h,vector<int>(w,-1));
	queue<pii> q;
	q.push(mkp(x1,y1));
	dist[x1][y1]=0;
	int mx=0;
	while(!q.empty()){
		int ui=q.front().first;
		int uj=q.front().second;
		q.pop();
		mx=max(mx,dist[ui][uj]);
		if(ui+1>=0 && ui+1<h && grid[ui+1][uj]!='#' && dist[ui+1][uj]==-1){
			dist[ui+1][uj]=dist[ui][uj]+1;
			q.push(mkp(ui+1,uj));
		}
		if(ui-1>=0 && ui-1<h && grid[ui-1][uj]!='#' && dist[ui-1][uj]==-1){
			dist[ui-1][uj]=dist[ui][uj]+1;
			q.push(mkp(ui-1,uj));
		}
		if(uj+1>=0 && uj+1<w && grid[ui][uj+1]!='#' && dist[ui][uj+1]==-1){
			dist[ui][uj+1]=dist[ui][uj]+1;
			q.push(mkp(ui,uj+1));
		}
		if(uj-1>=0 && uj-1<w && grid[ui][uj-1]!='#' && dist[ui][uj-1]==-1){
			dist[ui][uj-1]=dist[ui][uj]+1;
			q.push(mkp(ui,uj-1));
		}
	}
	return mx;
	
}

int solve()
{
	cin>>h>>w;	
	for(int i=0;i<h;i++){
		cin>>grid[i];
	}
	int mx=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(grid[i][j]!='#'){
				int x=dijkstra(i,j);
				mx=max(mx,x);
			}
		}
	}
	cout<<mx<<endl;
	return 0;
	
}
signed main()
{
	fastio;
//	test
		solve();
}