#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;
char m[20 + 5][20 + 5];
int h, w;
int dirs[][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
queue<T> q;
int mw[20 + 5][20 + 5];
int maxw;
void init() {
  maxw = 0;
  while (!q.empty()) q.pop();
  memset(mw, -1, sizeof(mw));
}
bool ok(int i, int j) {
  return i >= 1 && i <= h && j >= 1 && j <= w && m[i][j] == '.' &&
         mw[i][j] == -1;
}
void bfs(int i, int j, int w) {
  if (!ok(i, j)) return;
  q.push(make_tuple(i, j, w));
  while (!q.empty()) {
    tie(i, j, w) = q.front();
    q.pop();
    mw[i][j] = w;
    for (int d = 0; d < 4; d++) {
      int ti = i + dirs[d][0], tj = j + dirs[d][1];
      if (ok(ti, tj)) q.push(make_tuple(ti, tj, w + 1));
    }
  }
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) maxw = max(maxw, mw[i][j]);
}
int main(int argc, char *argv[]) {
  while (~scanf("%d %d", &h, &w)) {
    getchar();
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        m[i][j] = getchar();
      }
      getchar();
    }
    int ans = 0;
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= w; j++) {
        init();
        bfs(i, j, 0);
        ans = max(ans, maxw);
      }
    printf("%d\n", ans);
  }
}
