#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool> > v(h, vector<bool>(w));
  int n = h * w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.') v[i][j] = true;
    }
  }
  vector<vector<int> > dist(n, vector<int>(n, INT_MAX));
  for (int i = 0; i < n; i++) {
    int row = i / w;
    int col = i % w;
    if (!v[row][col]) continue;
    if (row > 0 && v[row - 1][col]) {
      dist[i][i - w] = 1;
      dist[i - w][i] = 1;
    }
    if (row < h - 1 && v[row + 1][col]) {
      dist[i][i + w] = 1;
      dist[i + w][i] = 1;
    }
    if (col > 0 && v[row][col - 1]) {
      dist[i][i - 1] = 1;
      dist[i - 1][i] = 1;
    }
    if (col < w - 1 && v[row][col + 1]) {
      dist[i][i + 1] = 1;
      dist[i + 1][i] = 1;
    }
  }
  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] == INT_MAX || dist[k][j] == INT_MAX) continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int max1 = INT_MIN;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dist[i][j] == INT_MAX) continue;
      max1 = max(max1, dist[i][j]);
    }
  }
  cout << max1 << "\n";
  return 0;
}
