#include <bits/stdc++.h>
using namespace std;
struct cont {
  long long dist, x, y;
};
signed main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  long long H, W;
  cin >> H >> W;
  vector<string> s(H);
  long long sx, sy;
  for (long long i = (0); i < (H); i++) cin >> s[i];
  long long ans = 0;
  long long dir[5] = {0, 1, 0, -1, 0};
  bool seen[50][50];
  for (long long i = (0); i < (H); i++) {
    for (long long j = (0); j < (W); j++) {
      sx = j;
      sy = i;
      memset(seen, false, sizeof(seen));
      queue<cont> q;
      q.push({0, sx, sy});
      while (q.size()) {
        long long dist = q.front().dist, x = q.front().x, y = q.front().y;
        q.pop();
        if (seen[y][x] == true) continue;
        seen[y][x] = true;
        ans = max(ans, dist);
        for (long long i = (0); i < (4); i++) {
          if (y + dir[i + 1] >= H || y + dir[i + 1] < 0 || x + dir[i] >= W ||
              x + dir[j] < 0)
            continue;
          else if (s[y + dir[i + 1]][x + dir[i]] == '.') {
            q.push({dist + 1, x + dir[i], y + dir[i + 1]});
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
