#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  while (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, false));
    vector<vector<bool>> foi2(n, vector<bool>(m, false));
    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] == false && mat[i][j] == '.') {
          long long dist_tmp = -1;
          pair<long long, long long> ini{};
          queue<pair<long long, long long>> fila;
          foi1[i][j] = true;
          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] == false &&
                  mat[a.first + p.first][a.second + p.second] == '.') {
                foi1[a.first + p.first][a.second + p.second] = true;
                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] = true;
          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] == false &&
                  mat[a.first + p.first][a.second + p.second] == '.') {
                foi2[a.first + p.first][a.second + p.second] = true;
                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;
}
