#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> dv = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; i++) cin >> v[i];
  int n = h * w;
  vector<vector<int>> d(n, vector<int>(n, 1e9));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i == j) d[i][i] = 0;
      if (v[i][j] == '#') continue;
      for (auto e : dv) {
        int x = i + e.first;
        int y = j + e.second;
        if (x < 0 || x >= h || y < 0 || y >= w) continue;
        if (v[x][y] == '#') continue;
        d[i * w + j][x * w + y] = 1;
        d[x * w + y][i * w + j] = 1;
      }
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
      }
    }
  }
  int ans = 1;
  for (auto v : d) {
    for (auto e : v) {
      if (e == 1e9) continue;
      ans = max(ans, e);
    }
  }
  cout << ans << endl;
  return 0;
}
