#include <bits/stdc++.h>
using namespace std;
static const int INF = 1 << 29;
static const int di[] = {-1, 0, 1, 0};
static const int dj[] = {0, -1, 0, 1};
int main() {
  int R, C;
  cin >> R >> C;
  vector<string> c(R);
  for (long long i = 0; i < (long long)(R); i++) cin >> c.at(i);
  vector<string> d(R);
  for (long long i = 0; i < (long long)(R); i++) d.at(i) = c.at(i);
  long long ans = 0;
  for (int sx = 0; sx < C; sx++) {
    for (int gx = 0; gx < C; gx++) {
      for (int sy = 0; sy < R; sy++) {
        for (int gy = 0; gy < R; gy++) {
          for (long long i = 0; i < (long long)(R); i++) c.at(i) = d.at(i);
          long long now = 0;
          vector<vector<int>> dp(R, vector<int>(C, INF));
          dp[sy][sx] = 0;
          queue<pair<int, int>> q;
          q.emplace(sy, sx);
          while (!q.empty()) {
            int i = q.front().first, j = q.front().second;
            q.pop();
            if (c[i][j] != '.') continue;
            for (int k = 0; k < 4; ++k) {
              int I = i + di[k], J = j + dj[k];
              if (I < 0 || R <= I || J < 0 || C <= J) continue;
              if (dp[I][J] < dp[i][j]) continue;
              if (c[I][J] != '.') continue;
              if (I == gy && J == gx) now = dp[i][j] + 1;
              dp[I][J] = dp[i][j] + 1;
              c[i][j] = '+';
              q.emplace(I, J);
            }
          }
          if (ans < now) ans = now;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
