#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int mod = 1e9 + 7;
int check(int n, int m, int h, int w) {
  if (n >= 0 && n < h && m >= 0 && m < w) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int h, w;
  cin >> h >> w;
  int start, start1;
  char a[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        start = i;
        start1 = j;
      }
    }
  }
  vector<vector<int>> dp(h, vector<int>(w, 0));
  int maxq = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      queue<pair<int, pair<int, int>>> q;
      q.push({0, {i, j}});
      vector<vector<int>> vp(h, vector<int>(w, 0));
      while (!q.empty()) {
        auto k = q.front();
        int f = k.first;
        int g = k.second.first;
        int d = k.second.second;
        q.pop();
        maxq = max(f, maxq);
        if (check(g + 1, d, h, w) == 1 && vp[g + 1][d] == 0 &&
            a[g][d + 1] == '.') {
          q.push({f + 1, {g + 1, d}});
          vp[g + 1][d] = 1;
        }
        if (check(g, d + 1, h, w) == 1 && vp[g][d + 1] == 0 &&
            a[g][d + 1] == '.') {
          q.push({f + 1, {g, d + 1}});
          vp[g][d + 1] = 1;
        }
        if (check(g - 1, d, h, w) == 1 && vp[g - 1][d] == 0 &&
            a[g - 1][d] == '.') {
          q.push({f + 1, {g - 1, d}});
          vp[g - 1][d] = 1;
        }
        if (check(g, d - 1, h, w) == 1 && vp[g][d - 1] == 0 &&
            a[g][d - 1] == '.') {
          q.push({f + 1, {g, d - 1}});
          vp[g][d - 1] = 1;
        }
      }
    }
  }
  cout << maxq << endl;
}
