#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 30;
const double PI = acos(-1);
int main() {
  int h, w;
  int ans = 0;
  cin >> h >> w;
  vector<string> s(h);
  vector<vector<int>> dis(h, vector<int>(w));
  queue<pair<int, int>> q;
  pair<int, int> at;
  for (int i = 0, i_len = (int)(h); i < i_len; i++) {
    cin >> s[i];
  }
  for (int i = 0, i_len = (int)(h); i < i_len; i++) {
    for (int j = 0, j_len = (int)(w); j < j_len; j++) {
      for (int I = 0, I_len = (int)(h); I < I_len; I++) {
        for (int J = 0, J_len = (int)(w); J < J_len; J++) {
          dis[I][J] = INF;
        }
      }
      at = make_pair(i, j);
      if (s[i][j] == '#') {
        continue;
      }
      dis[i][j] = 0;
      q.push(at);
      while (!q.empty()) {
        at = q.front();
        q.pop();
        for (int ni = at.first - 1; ni <= at.first + 1; ni++) {
          for (int nj = at.second - 1; nj <= at.second + 1; nj++) {
            if (ni < 0 or nj < 0 or ni == h or nj == w or
                !((ni == at.first) xor (nj == at.second))) {
              continue;
            }
            if (chmin(dis[ni][nj], dis[at.first][at.second] + 1) and
                s[ni][nj] == '.') {
              q.push(make_pair(ni, nj));
            }
          }
        }
      }
      for (int I = 0, I_len = (int)(h); I < I_len; I++) {
        for (int J = 0, J_len = (int)(w); J < J_len; J++) {
          if (dis[I][J] == INF) {
            continue;
          }
          chmax(ans, dis[I][J]);
        }
      }
    }
  }
  cout << ans << endl;
}
