#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> a(n + 2, vector<bool>(m + 2));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == '.') {
        a[i + 1][j + 1] = true;
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!a[i + 1][j + 1]) continue;
      vector<vector<int>> d(n, vector<int>(m, INT_MAX));
      d[i][j] = 0;
      vector<pair<int, int>> q;
      q.emplace_back(i, j);
      for (auto p : q) {
        int x = p.first;
        int y = p.second;
        res = max(res, d[x][y]);
        vector<int> dx = {-1, 0, 0, 1};
        vector<int> dy = {0, -1, 1, 0};
        for (int dir = 0; dir < 4; dir++) {
          int xx = x + dx[dir];
          int yy = y + dy[dir];
          if (a[xx + 1][yy + 1] && d[xx][yy] == INT_MAX) {
            d[xx][yy] = d[x][y] + 1;
            q.emplace_back(xx, yy);
          }
        }
      }
    }
  }
  cout << res << "\n";
  return 0;
}
