#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using Mat = vector<vector<ll>>;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> shw(H);
  for (auto &&sh : shw) {
    cin >> sh;
  }
  pair<int, int> ofs_tbl[] = {
      {1, 0},
      {-1, 0},
      {0, -1},
      {0, 1},
  };
  auto getid = [&](int y, int x) {
    if (y < 0 || y >= H) return -1;
    if (x < 0 || x >= W) return -1;
    return y * W + x;
  };
  auto getch = [&](int y, int x) -> char { return shw.at(y).at(x); };
  int num = H * W;
  Mat mat(num, vector<ll>(num, INT32_MAX));
  for (ll y = (0); y < (H); ++y) {
    for (ll x = (0); x < (W); ++x) {
      auto f = getid(y, x);
      if (f < 0) continue;
      if (getch(y, x) == '#') continue;
      for (const auto &ofs : ofs_tbl) {
        auto ey = y + ofs.first;
        auto ex = x + ofs.second;
        auto t = getid(ey, ex);
        if (t < 0) continue;
        if (getch(ey, ex) == '#') continue;
        mat[f][t] = 1;
        mat[t][f] = 1;
      }
    }
  }
  auto warshall_floyd = [&](int n) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          mat[j][k] = std::min(mat[j][k], mat[j][i] + mat[i][k]);
  };
  warshall_floyd(num);
  ll ans = 0;
  for (ll i = (0); i < (num); ++i) {
    for (ll j = (0); j < (num); ++j) {
      if (mat[i][j] >= INT32_MAX) continue;
      ans = max(ans, mat[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
