#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using vi = vector<long long>;
using vvi = vector<vi>;
using P = pair<long long, long long>;
long long h, w;
string s[22];
const long long inf = 1LL << 60;
signed main() {
  cin >> h >> w;
  for (long long i = (long long)(0); i < (long long)(h); i++) cin >> s[i];
  vvi dist(h * w, vi(h * w, inf));
  for (long long i = (long long)(0); i < (long long)(h); i++)
    for (long long j = (long long)(0); j < (long long)(w); j++) {
      if (s[i][j] == '#') continue;
      if (i + 1 < h and s[i + 1][j] != '#') {
        dist[i * w + j][(i + 1) * w + j] = 1;
        dist[(i + 1) * w + j][i * w + j] = 1;
      }
      if (j + 1 < w and s[i][j + 1] != '#') {
        dist[i * w + j][i * w + (j + 1)] = 1;
        dist[i * w + (j + 1)][i * w + j] = 1;
      }
    }
  for (long long k = (long long)(0); k < (long long)(h * w); k++)
    for (long long i = (long long)(0); i < (long long)(h * w); i++)
      for (long long j = (long long)(0); j < (long long)(h * w); j++) {
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
      }
  long long ans = 0;
  for (long long i = (long long)(0); i < (long long)(h * w); i++)
    for (long long j = (long long)(0); j < (long long)(h * w); j++) {
      if (dist[i][j] != inf) chmax(ans, dist[i][j]);
    }
  cout << ans << endl;
  return 0;
}
