#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  vector<vector<int>> d(h, vector<int>(w));
  vector<vector<bool>> t(h, vector<bool>(w));
  queue<tuple<int, int, int>> que;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) cin >> s[i][j];
  }
  int ans = 0;
  tuple<int, int, int> p;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      if (s[i][j] == '#') continue;
      t[i][j] = true;
      que.push(tuple<int, int, int>(i, j, 0));
      while (!que.empty()) {
        p = que.front();
        que.pop();
        d[get<0>(p)][get<1>(p)] = get<2>(p);
        if (get<0>(p) - 1 >= 0) {
          if (!t[get<0>(p) - 1][get<1>(p)] &&
              s[get<0>(p) - 1][get<1>(p)] == '.') {
            t[get<0>(p) - 1][get<1>(p)] = true;
            que.push(
                tuple<int, int, int>(get<0>(p) - 1, get<1>(p), get<2>(p) + 1));
          }
        }
        if (get<1>(p) - 1 >= 0) {
          if (!t[get<0>(p)][get<1>(p) - 1] &&
              s[get<0>(p)][get<1>(p) - 1] == '.') {
            t[get<0>(p)][get<1>(p) - 1] = true;
            que.push(
                tuple<int, int, int>(get<0>(p), get<1>(p) - 1, get<2>(p) + 1));
          }
        }
        if (get<0>(p) + 1 < h) {
          if (!t[get<0>(p) + 1][get<1>(p)] &&
              s[get<0>(p) + 1][get<1>(p)] == '.') {
            t[get<0>(p) + 1][get<1>(p)] = true;
            que.push(
                tuple<int, int, int>(get<0>(p) + 1, get<1>(p), get<2>(p) + 1));
          }
        }
        if (get<0>(p) + 1 < w) {
          if (!t[get<0>(p)][get<1>(p) + 1] &&
              s[get<0>(p)][get<1>(p) + 1] == '.') {
            t[get<0>(p)][get<1>(p) + 1] = true;
            que.push(
                tuple<int, int, int>(get<0>(p), get<1>(p) + 1, get<2>(p) + 1));
          }
        }
      }
      for (int k = 0; k < (int)(h); k++) {
        for (int l = 0; l < (int)(w); l++) {
          ans = max(ans, d[k][l]);
          t[k][l] = false;
          d[k][l] = 0;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
