#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<vector<int> > Matrix;
const int INF = 1000000000;
Matrix dist;
bool warshall_floyd(int n) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dist[i][k] != INF && dist[k][j] != INF) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (dist[i][i] < 0) return true;
  }
  return false;
}
const int dh[] = {1, -1, 0, 0};
const int dw[] = {0, 0, 1, -1};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  int n = H * W;
  dist.resize(n, vector<int>(n, INF));
  vector<string> s(H);
  for (int i = 0; i < H; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '#') continue;
      int pos1 = i * W + j;
      for (int k = 0; k < 4; ++k) {
        int ii = i + dh[k], jj = j + dw[k];
        if (ii < 0 || ii >= H || jj < 0 || jj >= W) continue;
        if (s[ii][jj] == '#') continue;
        int pos2 = ii * W + jj;
        dist[pos1][pos2] = 1;
      }
    }
  }
  warshall_floyd(n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (dist[i][j] >= INF) continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << "\n";
  return 0;
}
