#include <bits/stdc++.h>
using namespace std;
char s[111][111];
int dis[111][111];
bool vis[111][111];
int n, m;
int mx[10] = {0, 1, -1, 0, 0};
int my[10] = {0, 0, 0, 1, -1};
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> s[i][j];
  int maxx = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (s[i][j] != '.') continue;
      memset(dis, 0, sizeof(dis));
      memset(vis, 0, sizeof(vis));
      queue<pair<int, int> > q;
      q.push(make_pair(i, j));
      while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for (int k = 1; k <= 4; k++) {
          int xx = x + mx[k];
          int yy = y + my[k];
          if (xx < 1 || yy < 1 || xx > n || yy > m) continue;
          if (vis[xx][yy]) continue;
          if (s[xx][yy] != '.') continue;
          vis[xx][yy] = 1;
          q.push(make_pair(xx, yy));
          dis[xx][yy] = dis[x][y] + 1;
          maxx = max(maxx, dis[xx][yy]);
        }
      }
    }
  cout << maxx << endl;
}
