#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<string> mat(n);
  for (int i = 0; i < n; ++i) {
    cin >> mat[i];
  }
  vector<vector<bool>> foi1(n, vector<bool>(m));
  vector<vector<bool>> foi2(n, vector<bool>(m));
  vector<vector<long long>> dist1(n, vector<long long>(m));
  vector<vector<long long>> dist2(n, vector<long long>(m));
  vector<pair<long long, long long>> dir{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (foi1[i][j] == 0 && mat[i][j] == '.') {
        long long dist_tmp = -1;
        pair<long long, long long> ini{};
        queue<pair<long long, long long>> fila;
        foi1[i][j] = 1;
        fila.push({i, j});
        while (!fila.empty()) {
          auto a = fila.front();
          fila.pop();
          if (dist_tmp < dist1[a.first][a.second]) {
            dist_tmp = dist1[a.first][a.second];
            ini = a;
          }
          for (auto& p : dir) {
            if (0 <= a.first + p.first && a.first + p.first < n &&
                0 <= a.second + p.second && a.second + p.second < m &&
                foi1[a.first + p.first][a.second + p.second] == 0 &&
                mat[a.first + p.first][a.second + p.second] == '.') {
              foi1[a.first + p.first][a.second + p.second] = 1;
              fila.push({a.first + p.first, a.second + p.second});
              dist1[a.first + p.first][a.second + p.second] =
                  dist1[a.first][a.second] + 1;
            }
          }
        }
        foi2[ini.first][ini.second] = 1;
        fila.push({ini.first, ini.second});
        while (!fila.empty()) {
          auto a = fila.front();
          fila.pop();
          res = max(res, dist2[a.first][a.second]);
          for (auto& p : dir) {
            if (0 <= a.first + p.first && a.first + p.first < n &&
                0 <= a.second + p.second && a.second + p.second < m &&
                foi2[a.first + p.first][a.second + p.second] == 0 &&
                mat[a.first + p.first][a.second + p.second] == '.') {
              foi2[a.first + p.first][a.second + p.second] = 1;
              fila.push({a.first + p.first, a.second + p.second});
              dist2[a.first + p.first][a.second + p.second] =
                  dist2[a.first][a.second] + 1;
            }
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
