#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001000;
const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
int d4x[4] = {0, 1, 0, -1};
int d4y[4] = {1, 0, -1, 0};
int main() {
  int H, W;
  cin >> H >> W;
  char nap[H + 2][W + 2];
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j) cin >> nap[i][j];
  int ans = 0;
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j) {
      vector<vector<int>> e_ans(H + 2, vector<int>(W + 2, inf));
      queue<pair<int, int>> Q;
      Q.push(make_pair(i, j));
      e_ans[i][j] = 0;
      while (!Q.empty()) {
        int y = Q.front().first, x = Q.front().second;
        Q.pop();
        for (int k = 0; k < 4; ++k) {
          int dy = y + d4y[k], dx = x + d4x[k];
          if (nap[dy][dx] == '.' && e_ans[dy][dx] == inf) {
            e_ans[dy][dx] = e_ans[y][x] + 1;
            Q.push(make_pair(dy, dx));
          }
        }
      }
      int t_ans = 0;
      for (int k = 1; k <= H; ++k)
        for (int l = 1; l <= W; ++l) {
          if (e_ans[k][l] == inf) continue;
          t_ans = max(t_ans, e_ans[k][l]);
        }
      ans = max(ans, t_ans);
    }
  cout << ans << endl;
  return 0;
}
