#include <bits/stdc++.h>
using namespace std;
int stepX[4] = {1, -1, 0, 0};
int stepY[4] = {0, 0, 1, -1};
bool inArea(int tx, int ty, int w, int h) {
  return (0 <= tx && tx < w && 0 <= ty && ty < h);
}
int getFar(vector<vector<bool>> &mat, int sh, int sw, int h, int w) {
  queue<int> que;
  vector<int> steps(h * w, h * w);
  vector<bool> checker(w * h);
  que.push(sh * w + sw);
  steps[sh * w + sw] = 0;
  checker[sh * w + sw] = true;
  int dist = 0;
  while (!que.empty()) {
    int num = que.front();
    que.pop();
    int tx = num % w;
    int ty = num / w;
    int stp = steps[ty * w + tx];
    for (int i = 0; i < 4; ++i) {
      int ttx = tx + stepX[i];
      int tty = ty + stepY[i];
      if (inArea(ttx, tty, w, h) && mat[tty][ttx] && !checker[tty * w + ttx]) {
        que.push(tty * w + ttx);
        checker[tty * w + ttx] = true;
        steps[tty * w + ttx] = stp + 1;
        dist = max(dist, stp + 1);
      }
    }
  }
  return dist;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> mat(h);
  for (int i = 0; i < h; ++i) {
    vector<bool> row(w);
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      row[j] = c == '.';
    }
    mat[i] = row;
  }
  int ans = 0;
  for (int i = 0; i < h * w; ++i) {
    int tx = i % w;
    int ty = i / w;
    if (!mat[ty][tx]) {
      continue;
    }
    ans = max(ans, getFar(mat, tx, ty, h, w));
  }
  cout << ans << endl;
}
