#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn =  233;
int d[maxn][maxn];
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
char g[maxn][maxn];
queue<pair<int,int> > q;
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%s",g[i]+1);
	int ans = 0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)if(g[i][j]=='.'){
		memset(d,-1,sizeof(d));
		d[i][j] = 0;
		q.push(mp(i,j));
		while(!q.empty()){
		
			int x = q.front().fi;
			int y = q.front().se;
			q.pop();
			for(int i=0;i<4;i++){
				int nx = x+dx[i];
				int ny = y+dy[i];
				if(nx<1||ny<1||nx>n||ny>m)continue;
				if(d[nx][ny]!=-1)continue;
				if(g[nx][ny]=='#')continue;
				d[nx][ny] = d[x][y] + 1;
				q.push(mp(nx,ny));
				ans = max(ans,d[x][y]+1);
			}
			
		}
	}
	cout << ans << endl;
}
