#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1e18;
void mainsolve() {
  long long h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (long long i = 0; i < (h); ++i) cin >> s[i];
  long long res = 0;
  for (long long i = 0; i < (h); ++i)
    for (long long j = 0; j < (w); ++j) {
      pair<long long, long long> start = pair<long long, long long>(i, j);
      vector<vector<long long>> dp(h, vector<long long>(w, INF));
      dp[start.first][start.second] = 0;
      queue<pair<long long, long long>> q;
      q.push(start);
      while (!q.empty()) {
        pair<long long, long long> nowp = q.front();
        q.pop();
        for (long long i = 0; i < (4); ++i) {
          pair<long long, long long> nextp = pair<long long, long long>(
              nowp.first + dx[i], nowp.second + dy[i]);
          if (0 <= nextp.first && nextp.first < h && 0 <= nextp.second &&
              nextp.second < w && dp[nextp.first][nextp.second] == INF &&
              s[nextp.first][nextp.second] != '#') {
            q.push(nextp);
            dp[nextp.first][nextp.second] = dp[nowp.first][nowp.second] + 1;
          }
        }
      }
      for (long long a = 0; a < (h); ++a)
        for (long long b = 0; b < (w); ++b) {
          if (dp[a][b] != INF) res = max(res, dp[a][b]);
        }
    }
  cout << res << endl;
  return;
}
int main() {
  mainsolve();
  return 0;
}
