#include <bits/stdc++.h>
using namespace std;
using p = pair<long long, long long>;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
int main(void) {
  long long h, w;
  cin >> h >> w;
  string s[h];
  for (long long i = 0; i < h; i++) cin >> s[i];
  long long count = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (s[i][j] == '#') count++;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      vector<vector<long long>> dist(h, vector<long long>(w, 1e+9));
      vector<vector<long long>> use(h, vector<long long>(w, -1));
      queue<p> que;
      que.push(p(i, 0));
      use[i][0] = 1;
      dist[i][0] = 0;
      while (!que.empty()) {
        p check = que.front();
        long long x = check.first, y = check.second;
        que.pop();
        for (long long i = 0; i < 4; i++) {
          long long a = x + dx[i];
          long long b = y + dy[i];
          if (a < 0 || b < 0 || a >= h || b >= w) continue;
          if (use[a][b] != -1) continue;
          if (s[a][b] == '#') continue;
          que.push(p(a, b));
          dist[a][b] = min(dist[a][b], dist[x][y] + 1);
          use[a][b] = 1;
        }
      }
      for (long long i = 0; i < h; i++) {
        for (long long j = 0; j < w; j++) {
          if (s[i][j] == '.') ans = max(ans, dist[i][j]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
