#include <bits/stdc++.h>
using namespace std;
const long long MAX = 510000;
const long long MOD = 1000000007;
signed main() {
  long long h, w, k;
  cin >> h >> w;
  string s[h];
  for (long long i = 0; i < h; i++) cin >> s[i];
  long long dp[h][w];
  queue<pair<long long, long long>> que;
  pair<long long, long long> t;
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        t = make_pair(i, j);
        break;
      }
    }
  long long maxa = 0;
  for (long long i0 = 0; i0 < h; i0++)
    for (long long j0 = 0; j0 < w; j0++) {
      t = make_pair(i0, j0);
      for (long long i = 0; i < h; i++)
        for (long long j = 0; j < w; j++) dp[i][j] = -1;
      dp[t.first][t.second] = 0;
      que.push(t);
      while (!que.empty()) {
        t = que.front();
        k = dp[t.first][t.second];
        que.pop();
        if (t.first > 0 && dp[t.first - 1][t.second] == -1 &&
            s[t.first - 1][t.second] == '.') {
          dp[t.first - 1][t.second] = k + 1;
          que.push(make_pair(t.first - 1, t.second));
        }
        if (t.first < h - 1 && dp[t.first + 1][t.second] == -1 &&
            s[t.first + 1][t.second] == '.') {
          dp[t.first + 1][t.second] = k + 1;
          que.push(make_pair(t.first + 1, t.second));
        }
        if (t.second > 0 && dp[t.first][t.second - 1] == -1 &&
            s[t.first][t.second - 1] == '.') {
          dp[t.first][t.second - 1] = k + 1;
          que.push(make_pair(t.first, t.second - 1));
        }
        if (t.second < w - 1 && dp[t.first][t.second + 1] == -1 &&
            s[t.first][t.second + 1] == '.') {
          dp[t.first][t.second + 1] = k + 1;
          que.push(make_pair(t.first, t.second + 1));
        }
      }
      for (long long i = 0; i < h; i++)
        for (long long j = 0; j < w; j++) {
          if (maxa < dp[i][j]) {
            maxa = dp[i][j];
          }
        }
    }
  cout << maxa;
  return 0;
}
