#include <bits/stdc++.h>
using namespace std;
struct aaa {
  aaa() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} aaa;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long bfs(int i, int j, const int& h, const int& w,
              const vector<string>& s) {
  int res = -1;
  vector<vector<int>> d(h, vector<int>(w, -1));
  queue<pair<pair<int, int>, int>> q;
  q.emplace(pair<int, int>(i, j), 0);
  while (!q.empty()) {
    int x, y, c;
    pair<int, int> p;
    tie(p, c) = q.front();
    q.pop();
    tie(y, x) = p;
    if (x < 0 || w <= x) continue;
    if (y < 0 || h <= y) continue;
    if (d[y][x] != -1) continue;
    if (s[y][x] != '.') continue;
    d[y][x] = c;
    res = max(res, c);
    for (int i = 0; i < 4; i++) {
      q.emplace(pair<int, int>(y + dy[i], x + dx[i]), c + 1);
    }
  }
  return res;
}
int main() {
  int h, w;
  long long ans = -1;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        ans = max(ans, bfs(j, i, h, w, s));
      }
    }
  }
  cout << ans << endl;
}
