#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> s(h, vector<bool>(w, false));
  char c;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c;
      if (c == '.') s[i][j] = true;
    }
  }
  vector<vector<int>> d(h * w, vector<int>(h * w, 400));
  for (int x = 0; x < h; x++) {
    for (int y = 0; y < w; y++) {
      if (s[x][y]) {
        if (y > 0 && s[x][y - 1]) d[x * w + y][x * w + y - 1] = 1;
        if (y + 1 < w && s[x][y + 1]) d[x * w + y][x * w + y + 1] = 1;
        if (x > 0 && s[x - 1][y]) d[x * w + y][(x - 1) * w + y] = 1;
        if (x + 1 < h && s[x + 1][y]) d[x * w + y][(x + 1) * w + y] = 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++)
        if (d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
  int ans = 0;
  for (int i = 0; i < h * w; i++)
    for (int j = 0; j < h * w; j++)
      if (d[i][j] < 400 && ans < d[i][j]) ans = d[i][j];
  cout << ans << endl;
}
