#include <bits/stdc++.h>
using namespace std;
const int INF = 1e5;
int main() {
  int h, w, V;
  cin >> h >> w;
  V = h * w;
  vector<vector<int>> d(V, vector<int>(V, INF));
  for (int i = 0; i < V; i++) {
    d[i][i] = 0;
  }
  vector<vector<char>> c(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
    }
  }
  vector<int> dx = {1, 0, -1, 0};
  vector<int> dy = {0, 1, 0, -1};
  for (int x = 0; x < h; x++) {
    for (int y = 0; y < w; y++) {
      for (int i = 0; i < 4; i++) {
        if (0 <= x + dx[i] && x + dx[i] < h && 0 <= y + dy[i] &&
            y + dy[i] < w && c[x + dx[i]][y + dy[i]] == '.') {
          d[w * x + y][w * (x + dx[i]) + y + dy[i]] = 1;
        }
      }
    }
  }
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (d[i][j] != INF) ans = max(ans, d[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
