#include<bits/stdc++.h>
using namespace std;
#define ll long long int

void dfs(vector<string > &vec,vector< vector<ll> > &visited,ll a,ll b,ll count,ll h,ll w){
	if(a>=h||b>=w||a<0||b<0){
		return;
	}
	if(vec[a][b]=='#') return;
	if(visited[a][b]>0) return;
	visited[a][b]=count;
	dfs(vec,visited,a+1,b,count+1,h,w);
	dfs(vec,visited,a-1,b,count+1,h,w);
	dfs(vec,visited,a,b+1,count+1,h,w);
	dfs(vec,visited,a,b-1,count+1,h,w);
}

int main()
{
	ll h,w;
	cin>>h>>w;
	vector<string > vec;
	for(ll i=1;i<=h;i++){
		string s;
		cin>>s;
		vec.push_back(s);
	}
	
	
	ll ans=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(vec[i][j]=='.'){
				vector< vector<ll> > visited(h,vector<ll> (w,0));
				ll count=1;
				dfs(vec,visited,i,j,count,h,w);
//				cout<<i<<" "<<j<<"   pp"<<endl;
				for(ll k=0;k<h;k++){
					for(ll l=0;l<w;l++){
						count=max(count,visited[k][l]-1);
//						cout<<visited[k][l]-1<<" ";
					}
//					cout<<endl;
				}//cout<<endl;
				ans=max(ans,count);
			}
		}
	}
	cout<<min(ans,m+n-2)<<endl;
	
}