#include <bits/stdc++.h>
 
using namespace std;
 
int n, m, mx;
vector<vector<char>> grid(1 + n + 1, vector<char>(1 + m + 1, '#'));
 
struct point {
	int i, j;
  	point() {}
  	point(int _i, int _j)
      :i(_i)
      ,j(_j)
    {}
};
 
void BFS(point s) {
	vector<vector<int>> dist(1 + n + 1, vector<int>(1 + m + 1, -1));
  	queue<point> q;
    q.push(s);
    dist[s.i][s.j] = 0;
  	while (!q.empty()) {
    	int i = q.front().i;
      	int j = q.front().j;
      	q.pop();
        for (int di = -1; di <= 1; ++di)
          	for (int dj = -1; dj <= 1; ++dj) 
            	if (di * di + dj * dj == 1) {
            		int ni = i + di;
                	int nj = j + dj;
                	if (grid[ni][nj] == '#') continue;
              		if (dist[ni][nj] != -1) continue;
              		dist[ni][nj] = dist[i][j] + 1;
                	q.push(point(ni, nj));
            	}
    }
  	for (int i = 1; i <= n; ++i)
      	for (int j = 1; j <= m; ++j)
        	mx = max(mx, dist[i][j]);
  	return;
}
 
int main() {
  cin >> n >> m;
  
  for (int i = 1; i <= n; ++i)
    	for (int j = 1; j <= m; ++j) cin >> grid[i][j];
  
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) 
    	if (grid[i][j] != '#') BFS(point(i, j)));
  
  cout << mx << '\n';
  return 0;
}