#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
const int MOD = 1e9 + 7;
const long long INF = 1e+14;
const double PI = 3.14159265349;
void warshall_floyd(long long N, vector<vector<long long>>& d) {
  for (long long(k) = 0; (k) < (N); (k)++) {
    for (long long(i) = 0; (i) < (N); (i)++) {
      for (long long(j) = 0; (j) < (N); (j)++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (long long(i) = 0; (i) < (H); (i)++) {
    cin >> s[i];
  }
  vector<vector<long long>> d(H * W, vector<long long>(H * W, INF));
  for (long long(i) = 0; (i) < (H); (i)++) {
    for (long long(j) = 0; (j) < (W); (j)++) {
      if (i > 0) d[i * W + j][(i - 1) * W + j] = (s[i][j] == '.') ? 1 : INF;
      if (i < H - 1) d[i * W + j][(i + 1) * W + j] = (s[i][j] == '.') ? 1 : INF;
      if (j > 0) d[i * W + j][i * W + j - 1] = (s[i][j] == '.') ? 1 : INF;
      if (j < W - 1) d[i * W + j][i * W + j + 1] = (s[i][j] == '.') ? 1 : INF;
    }
  }
  warshall_floyd(H * W, d);
  long long ans = -INF;
  for (long long(i) = 0; (i) < (H * W); (i)++) {
    for (long long(j) = 0; (j) < (H * W); (j)++) {
      if (s[i / W][i % W] == '.' && s[j / W][j % W] == '.')
        ans = max(ans, d[i][j]);
    }
  }
  cout << ans << "\n";
  return 0;
}
