#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
int main() {
  int h, w;
  cin >> h >> w;
  int n = h * w;
  string s[h];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int d[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = INF;
    }
    d[i][i] = 0;
  }
  const int dx[] = {-1, 0, 0, 1};
  const int dy[] = {0, -1, 1, 0};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      for (int k = 0; k < 4; k++) {
        int nx = i + dx[k];
        int ny = j + dy[k];
        if (nx < 0 || h <= nx || ny < 0 || w <= ny || s[nx][ny] == '#')
          continue;
        d[h * i + j][h * nx + ny] = 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 = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][j] != INF) {
        ans = max(ans, d[i][j]);
      }
    }
  }
  cout << ans << endl;
}
