#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e6;
const int MaxN = 400;
int dist[MaxN][MaxN];
int h, w;
vector<string> s;
void solve() {
  int nv = h * w;
  for (int i = 0; i < nv; i++) {
    for (int j = 0; j < nv; j++) dist[i][j] = Inf;
  }
  int idx, idx2;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      idx = i * w + j;
      dist[idx][idx] = 0;
      if (i - 1 >= 0) {
        idx2 = (i - 1) * w + j;
        dist[idx][idx2] = 1;
      }
      if (i + 1 < h) {
        idx2 = (i + 1) * w + j;
        dist[idx][idx2] = 1;
      }
      if (j - 1 >= 0) {
        idx2 = i * w + j - 1;
        dist[idx][idx2] = 1;
      }
      if (j + 1 < w) {
        idx2 = i * w + j + 1;
        dist[idx][idx2] = 1;
      }
    }
  }
  for (int k = 0; k < nv; k++) {
    for (int i = 0; i < nv; i++) {
      for (int j = 0; j < nv; j++) {
        int tmp = (dist[i][k] == Inf || dist[k][j] == Inf)
                      ? Inf
                      : (dist[i][k] + dist[k][j]);
        if (dist[i][j] > tmp) dist[i][j] = tmp;
      }
    }
  }
  int dmax = 0;
  for (int i = 0; i < nv; i++) {
    for (int j = 0; j < nv; j++) {
      if (dist[i][j] != Inf) dmax = max(dmax, dist[i][j]);
    }
  }
  cout << dmax << endl;
}
int main() {
  string si;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> si;
    s.push_back(si);
  }
  solve();
  return 0;
}
