#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s[i];
  vector<vector<int>> dist(h, vector<int>(w, -1));
  queue<pair<int, int>> que;
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      dist[i][j] = 0;
      que.push({i, j});
      while (!que.empty()) {
        int u = que.front().first;
        int v = que.front().second;
        que.pop();
        for (int k = 0; k < 4; k++) {
          int nu = u + dx[k];
          int nv = v + dy[k];
          if (nu < 0 || nu >= h || nv < 0 || nv >= w) continue;
          if (dist[nu][nv] != -1) continue;
          que.push({nu, nv});
          dist[nu][nv] = dist[u][v] + 1;
          ans = max(ans, dist[nu][nv]);
        }
      }
    }
  }
  cout << ans << endl;
}
