#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long n, m, ans;
string str;
long long d[505][505];
void floydwarshall() {
  for (long long k = 0; k <= 504; ++k) {
    for (long long i = 0; i <= 504; ++i) {
      for (long long j = 0; j <= 504; ++j) {
        if (d[i][k] < 1000000000000000 && d[k][j] < 1000000000000000)
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
long long solve() {
  long long h, w;
  cin >> h >> w;
  vector<string> c(h);
  for (long long i = 0; i <= h - 1; ++i) {
    cin >> c[i];
  }
  long long a[h][w];
  for (long long i = 0; i <= h - 1; ++i) {
    for (long long j = 0; j <= w - 1; ++j) {
      a[i][j] = i * h + j;
    }
  }
  for (long long i = 0; i <= 504; ++i) {
    for (long long j = 0; j <= 504; ++j) {
      if (i == j)
        d[i][j] = 0;
      else if (!d[i][j])
        d[i][j] = 1000000000000000;
    }
  }
  for (long long i = 0; i <= h - 1; ++i) {
    for (long long j = 0; j <= w - 1; ++j) {
      if (c[i][j] == '.') {
        if (i > 0 && c[i - 1][j] == '.') {
          d[a[i][j]][a[i - 1][j]] = 1;
        }
        if (j > 0 && c[i][j - 1] == '.') {
          d[a[i][j]][a[i][j - 1]] = 1;
        }
        if (i < h - 1 && c[i + 1][j] == '.') {
          d[a[i][j]][a[i + 1][j]] = 1;
        }
        if (j < w - 1 && c[i][j + 1] == '.') {
          d[a[i][j]][a[i][j + 1]] = 1;
        }
      }
    }
  }
  floydwarshall();
  for (long long i = 0; i <= h * w - 1; ++i) {
    for (long long j = 0; j <= h * w - 1; ++j) {
      if (d[i][j] != 1000000000000000) ans = max(ans, d[i][j]);
    }
  }
  cout << ans;
  return 0;
}
signed main() {
  ios::sync_with_stdio(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
