#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF_LL = (long long)1000000007 * 1000000007;
const long long INF_INT = (long long)1000000007;
const double PI = 3.14159265358979323846;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  long long H, W;
  cin >> H >> W;
  vector<string> second(H);
  for (long long i = (0); i < (H); ++i) {
    cin >> second[i];
  }
  long long N = H * W;
  vector<vector<long long>> d(N, vector<long long>(N, INF_LL));
  for (long long i = (0); i < (N); ++i) {
    d[i][i] = 0;
  }
  for (long long i = (0); i < (N); ++i) {
    long long w = i % W;
    long long h = i / W;
    for (long long j = (0); j < (4); ++j) {
      if (second[h][w] == '.') {
        long long nw = w + dx[j];
        long long nh = h + dy[j];
        if (nw >= 0 && nw < W && nh >= 0 && nh < H) {
          if (second[nh][w] == '.') {
            d[i][nh * W + nw] = 1;
            d[nh * W + nw][i] = 1;
          }
        }
      }
    }
  }
  for (long long i = (0); i < (N); ++i) {
    for (long long j = (0); j < (N); ++j) {
      for (long long k = (0); k < (N); ++k) {
        chmin(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }
  long long ans = 0;
  for (long long i = (0); i < (N); ++i) {
    for (long long j = (0); j < (N); ++j) {
      if (d[i][j] != INF_LL) {
        chmax(ans, d[i][j]);
      }
    }
  }
  cout << ans << endl;
}
