#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#') continue;
      map<pair<int, int>, int> d;
      queue<pair<int, int>> q;
      q.push({i, j});
      d[{i, j}] = 0;
      while (!q.empty()) {
        auto p = q.front();
        q.pop();
        ans = max(ans, d[p]);
        auto [x, y] = p;
        if (x > 0 && d.count({x - 1, y}) == 0 && a[x - 1][y] == '.') {
          q.push({x - 1, y});
          d[{x - 1, y}] = d[{x, y}] + 1;
        }
        if (y > 0 && d.count({x, y - 1}) == 0 && a[x][y - 1] == '.') {
          q.push({x, y - 1});
          d[{x, y - 1}] = d[{x, y}] + 1;
        }
        if (x + 1 < n && d.count({x + 1, y}) == 0 && a[x + 1][y] == '.') {
          q.push({x + 1, y});
          d[{x + 1, y}] = d[{x, y}] + 1;
        }
        if (y + 1 < m && d.count({x, y + 1}) == 0 && a[x][y + 1] == '.') {
          q.push({x, y + 1});
          d[{x, y + 1}] = d[{x, y}] + 1;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
