#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int, int>;
int h, w, x, y, dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0}, ans;
char s[25][25];
int main(){
	scanf("%d%d", &h, &w);
	rep(i,h) scanf("\n%s", s[i+1]+1);
	rep(i,h) rep(j,w) if(s[i+1][j+1] == '.'){
		int dist[25][25] = {}, m = 0;
		queue<P> qu;
		qu.push(P{i+1,j+1});
		dist[i+1][j+1] = 1;
		while(!qu.empty()){
			tie(x,y) = qu.front(); qu.pop();
			rep(i,4){
				int nx = x + dx[i], ny = y + dy[i];
				if(dist[nx][ny] || s[nx][ny] != '.') continue;
				dist[nx][ny] = dist[x][y] + 1;
				m = max(m, dist[nx][ny]);
				qu.push(P{nx,ny});
			}
		}
		ans = max(ans,m-1);
	}
	printf("%d\n", ans);
}