#include <bits/stdc++.h>
using namespace std;
long long d[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
struct S {
  long long y, x, cnt;
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (long long i = 0, i_len = (h); i < i_len; i++) cin >> s[i];
  long long ans = 0;
  for (long long i = 0, i_len = (h); i < i_len; i++) {
    for (long long ii = 0, ii_len = (w); ii < ii_len; ii++) {
      long long tmp = 0;
      vector<vector<long long>> ss(h, vector<long long>(w, LONG_LONG_MAX));
      queue<S> q;
      q.push((S){i, ii, 0});
      while (!q.empty()) {
        S pos = q.front();
        q.pop();
        for (long long iii = 0, iii_len = (4); iii < iii_len; iii++) {
          long long nx = d[iii][0] + pos.x;
          long long ny = d[iii][1] + pos.y;
          if ((nx < 0) || (nx >= w) || (ny < 0) || (ny >= h) ||
              (s[ny][nx] == '#'))
            continue;
          if (ss[ny][nx] < (pos.cnt + 1)) continue;
          tmp = max(tmp, pos.cnt + 1);
          ss[ny][nx] = pos.cnt + 1;
          q.push((S){ny, nx, pos.cnt + 1});
        }
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
