#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  bool s[400];
  int d[400][400];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      s[i * w + j] = c == '.';
    }
  }
  queue<pair<int, int>> q;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (not s[i] || not s[j]) {
        d[i][j] = 40000;
      } else if (i == j) {
        d[i][j] = 0;
      } else {
        d[i][j] = 40000;
        if (i < j) q.emplace(i, j);
      }
    }
  }
  while (not q.empty()) {
    int p = q.front().first;
    int x = p / w;
    int y = p % w;
    int k = q.front().second;
    q.pop();
    for (int i = max(0, x - 1); i < min(h, x + 2); i++) {
      for (int j = max(0, y - 1); j < min(w, y + 2); j++) {
        if ((x - i) * (y - j) != 0) continue;
        if (not s[i * w + j]) continue;
        d[p][k] = min(d[p][k], d[i * w + j][k] + 1);
        d[k][p] = d[p][k];
      }
    }
    if (d[p][k] == 40000) {
      q.emplace(p, k);
    }
  }
  int m = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (d[i][j] == 40000) continue;
      m = max(d[i][j], m);
    }
  }
  cout << m << endl;
  return 0;
}
