#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, i, j, ans = 0, c, x, y, cx, cy;
  cin >> h >> w;
  pair<int, int> p;
  vector<vector<int> > m(h, vector<int>(w, 500)), mx(h, vector<int>(w, 500));
  for (i = 0; i < h; i++)
    for (j = 0; j < w; j++) {
      char k;
      cin >> k;
      if (k == '.')
        m[i][j] = 1;
      else
        m[i][j] = -1;
    }
  queue<pair<int, int> > v;
  for (i = 0; i < h; i++)
    for (j = 0; j < w; j++) {
      p = {i, j};
      mx[i][j] = 0;
      v.push(p);
      while (!v.empty()) {
        p = v.front();
        v.pop();
        x = p.first, y = p.second;
        cx = x - 1, cy = y;
        if (cx >= 0 && cx < h && cy >= 0 && cy < w && m[cx][cy] == 1 &&
            mx[x][y] < mx[cx][cy]) {
          mx[cx][cy] = mx[x][y] + 1;
          v.push({cx, cy});
        }
        cx = x + 1, cy = y;
        if (cx >= 0 && cx < h && cy >= 0 && cy < w && m[cx][cy] == 1 &&
            mx[x][y] < mx[cx][cy]) {
          mx[cx][cy] = mx[x][y] + 1;
          v.push({cx, cy});
        }
        cx = x, cy = y - 1;
        if (cx >= 0 && cx < h && cy >= 0 && cy < w && m[cx][cy] == 1 &&
            mx[x][y] < mx[cx][cy]) {
          mx[cx][cy] = mx[x][y] + 1;
          v.push({cx, cy});
        }
        cx = x, cy = y + 1;
        if (cx >= 0 && cx < h && cy >= 0 && cy < w && m[cx][cy] == 1 &&
            mx[x][y] < mx[cx][cy]) {
          mx[cx][cy] = mx[x][y] + 1;
          v.push({cx, cy});
        }
      }
      for (x = 0; x < h; x++) {
        for (y = 0; y < w; y++)
          if (mx[x][y] < 500) {
            if (mx[x][y] > ans) ans = mx[x][y];
            mx[x][y] = 500;
          }
      }
    }
  cout << ans;
}
