#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long mod = 998244353;
int inf = 1000001000;
long long INF = 1e18 + 5;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(w + 2, vector<int>(h + 2, 1));
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      char s;
      cin >> s;
      if (s == '.') a[j + 1][i + 1] = 0;
    }
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (a[j][i] == 1) continue;
      vector<vector<int>> b = a;
      queue<pair<pair<int, int>, int>> q;
      q.push(make_pair(make_pair(j, i), 0));
      while (!q.empty()) {
        int f = q.front().first.first, g = q.front().first.second,
            e = q.front().second;
        ans = max(ans, e);
        q.pop();
        if (b[f + 1][g] == 0) {
          b[f + 1][g] = 1;
          q.push(make_pair(make_pair(f + 1, g), e + 1));
        }
        if (b[f - 1][g] == 0) {
          b[f - 1][g] = 1;
          q.push(make_pair(make_pair(f - 1, g), e + 1));
        }
        if (b[f][g + 1] == 0) {
          b[f][g + 1] = 1;
          q.push(make_pair(make_pair(f, g + 1), e + 1));
        }
        if (b[f][g - 1] == 0) {
          b[f][g - 1] = 1;
          q.push(make_pair(make_pair(f, g - 1), e + 1));
        }
      }
    }
  }
  cout << ans << endl;
}
