#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<vector<int> > s(h, vector<int>(w));
  for (int i = 0; i < h; ++i) {
    string si;
    cin >> si;
    for (int j = 0; j < w; ++j) {
      if (si[j] == '#') {
        s[i][j] = 1;
      } else {
        s[i][j] = 0;
      }
    }
  }
  int n = h * w;
  vector<vector<int> > d(n, vector<int>(n, 1000000000));
  vector<int> field(n);
  for (int i = 0; i < n; ++i) {
    int y = i / w;
    int x = i % w;
    if (s[y][x] == 1) {
      field[i] = 1;
      continue;
    }
    field[i] = 0;
    for (int j = 0; j < 4; ++j) {
      if (x + dx[j] >= 0 && x + dx[j] < w && y + dy[j] >= 0 && y + dy[j] < h) {
        if (s[y + dy[j]][x + dx[j]] == 0) {
          int next = w * (y + dy[j]) + x + dx[j];
          d[i][next] = 1;
          d[next][i] = 1;
        }
      }
    }
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (field[i] == 0 && field[j] == 0) {
        ans = max(ans, d[i][j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
