#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  bool flag = false;
  long long ans = 0, sum = 0;
  long long mxd1 = -1, mxd2 = -1;
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  vector<vector<int>> d1(w * h, vector<int>(w * h, 1001001001));
  for (int i = 0, _i = (h); i < _i; ++i) cin >> g[i];
  for (int i = 0, _i = (h); i < _i; ++i) {
    for (int j = 0, _i = (w); j < _i; ++j) {
      if (g[i][j] == '#') continue;
      d1[i * w + j][i * w + j] = 0;
      for (int k = 0, _i = (4); k < _i; ++k) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (0 <= ni && ni < h && 0 <= nj && nj < w && g[ni][nj] == '.') {
          d1[i * w + j][ni * w + nj] = 1;
        }
      }
    }
  }
  for (int i = 0, _i = (w * h); i < _i; ++i) {
    for (int j = 0, _i = (w * h); j < _i; ++j) {
      for (int k = 0, _i = (w * h); k < _i; ++k) {
        if (g[k / w][k % w] == '#') continue;
        if (chmin(d1[i][j], d1[i][k] + d1[k][j])) {
          if (d1[i][j] > abs(i / w - j / w) + abs(i % w - j % w)) continue;
          if (chmax(ans, d1[i][j])) {
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
