#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 1000000007;
const long long LINF = 1LL << 60;
const int INF = 1 << 30;
int dx[] = {1, 0, 0, -1, 1, -1, 1, -1};
int dy[] = {0, 1, -1, 0, 1, -1, -1, 1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      queue<pair<int, pair<long long, long long>>> q;
      q.push(make_pair(0, make_pair(i, j)));
      vector<vector<int>> dp(h + 1, vector<int>(w + 1, INF));
      dp[i][j] = 0;
      while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int c = p.first;
        int x = p.second.second, y = p.second.first;
        for (int k = 0; k < 4; k++) {
          int ny = y + dy[k], nx = x + dx[k];
          if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] != '#') {
            if (chmin(dp[ny][nx], c + 1)) {
              q.push(make_pair(c + 1, make_pair(ny, nx)));
            }
          }
        }
      }
      for (int l = 0; l < h; l++) {
        for (int r = 0; r < w; r++) {
          if (dp[l][r] == INF) continue;
          ans = max(ans, dp[l][r]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
