#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char x;
  vector<vector<bool>> maze(h, vector<bool>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> x;
      if (x == '.')
        maze[i][j] = 1;
      else
        maze[i][j] = 0;
    }
  }
  vector<int> dx = {0, 0, 1, -1};
  vector<int> dy = {1, -1, 0, 0};
  vector<vector<long long>> y(h * w, vector<long long>(h * w, 1e9));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!maze[i][j]) continue;
      for (int k = 0; k < 4; k++) {
        if (i + dx[k] < 0 || i + dx[k] >= h) continue;
        if (j + dy[k] < 0 || j + dy[k] >= w) continue;
        if (maze[i + dx[k]][j + dy[k]])
          y[i * h + j][(i + dx[k]) * h + (j + dy[k])] = 1;
      }
    }
  }
  for (int k = 0; k < h * w; k++) {
    for (int i = 0; i < h * w; i++) {
      for (int j = 0; j < h * w; j++) y[i][j] = min(y[i][j], y[i][k] + y[k][j]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (y[i][j] >= 1e9) continue;
      ans = max(ans, y[i][j]);
    }
  }
  cout << ans << endl;
}
