#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
//#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define nax (ll)1e13
typedef long long ll;
typedef unsigned long long ull;
class solution{
public:
	int vertices=0;
	//int edges;
	vector<int> positions;
	vector<int> distance;
	vector<int> adj[402];
	void add(int u,int v){
		adj[u].pb(v);
	}
	
	char mat[20][20];
	void solve(){
		//int h,w;
		int w,h;
		cin>>h>>w;
		
		for(int i =0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>mat[i][j];
				vertices++;
			}	
		}
		for(int i =0;i<h;i++){
			for(int j=0;j<w;j++){
				if(mat[i][j] == '.'){
					if(i-1>=0){
						if(mat[i-1][j] == '.'){
							add(i*w+j+1,(i-1)*w+j+1);
						}
					}
					if(i+1>=0){
						if(mat[i+1][j] == '.'){
							add(i*w+j+1,(i+1)*w+j+1);
						}
					}
					if(j-1>=0){
						if(mat[i][j-1] == '.'){
							add(i*w+j+1,(i)*w+j);
						}
					}
					if(j+1>=0){
						if(mat[i][j+1] == '.'){
							add(i*w+j+1,(i)*w+j+2);
						}
					}
				}
				else{
					positions.pb(i*w+j+1);
				}
			}
		}
		int ans = 0;
		for(int i =0;i<h;i++){
			for(int j=0;j<w;j++){
				if(mat[i][j] == '.'){
					distance.resize(h*w+1,0);
					for(auto it : positions){
						distance[it] = -1;
					}
					distance[i*w+j+1] = ;
					bfs(i*w+j+1);
					ans = max(ans,*max_element(distance.begin(),distance.end()));
				}
				
			}	
		}
		cout<<ans;
	}
		void bfs(int u) 
	{ 
    	queue<int> q; 
    	q.push(u);
		vector<bool > v(vertices+1,false); 
    	v[u] = true; 
    	while (!q.empty()) { 
        	int f = q.front(); 
        	q.pop(); 
  
        //cout << f << " "; 
  
        // Enqueue all adjacent of f and mark them visited  
        	for (auto it : adj[f]) { 
            	if (!v[it]) { 
                q.push(it); 
                v[it] = true;
				distance[it] = distance[f]+1; 
            } 
        } 
    } 
} 

};

int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}

