#include <bits/stdc++.h>
using namespace std;
long long mei(vector<string> &S, long long H, long long W, long long x,
              long long y) {
  vector<vector<long long>> n(H, vector<long long>(W, 100000));
  queue<vector<long long>> q;
  q.push({x, y, 0});
  while (!q.empty()) {
    vector<long long> v = q.front();
    long long h = v[0], w = v[1], m = v[2];
    q.pop();
    if (h > 0 && S[h - 1][w] == '.' && n[h - 1][w] > 10000) {
      n[h - 1][w] = m + 1;
      q.push({h - 1, w, m + 1});
    }
    if (h < H - 1 && S[h + 1][w] == '.' && n[h + 1][w] > 10000) {
      n[h + 1][w] = m + 1;
      q.push({h + 1, w, m + 1});
    }
    if (w > 0 && S[h][w - 1] == '.' && n[h][w - 1] > 10000) {
      n[h][w - 1] = m + 1;
      q.push({h, w - 1, m + 1});
    }
    if (w < W - 1 && S[h][w + 1] == '.' && n[h][w + 1] > 10000) {
      n[h][w + 1] = m + 1;
      q.push({h, w + 1, m + 1});
    }
  }
  long long ans = 0;
  for (long long h = 0; h < (long long)(H); h++)
    for (long long w = 0; w < (long long)(W); w++)
      if (S[h][w] == '.') ans = max(ans, n[h][w]);
  return ans;
}
signed main() {
  long long H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (long long i = 0; i < (long long)(H); i++) cin >> S[i];
  long long ans = 0;
  for (long long h = 0; h < (long long)(H); h++)
    for (long long w = 0; w < (long long)(W); w++)
      ans = max(ans, mei(S, H, W, h, w));
  cout << ans << endl;
}
