#include <bits/stdc++.h>
using namespace std;
int ans, cnt, h, w, a[30][30], chk[30][30], dx[4] = {0, 1, 0, -1},
                                            dy[4] = {1, 0, -1, 0};
struct point {
  int x;
  int y;
  int num;
};
bool safe(int x, int y) {
  return (x >= 0 && x < h && y >= 0 && y < w && a[x][y] && (!chk[x][y]));
}
void bfs(int x0, int y0) {
  queue<point> Q;
  Q.push({x0, y0, 0});
  while (!Q.empty()) {
    int x = Q.front().x;
    int y = Q.front().y;
    int num = Q.front().num;
    chk[x][y] = 1;
    cnt = max(cnt, num);
    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i];
      int yy = y + dy[i];
      if (safe(xx, yy)) {
        Q.push({xx, yy, num + 1});
      }
    }
    Q.pop();
  }
}
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    char b[30];
    scanf("%s", b);
    for (int j = 0; j < w; j++) {
      if (b[j] == '.') {
        a[i][j] = 1;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          chk[i][j] = 0;
        }
      }
      cnt = 0;
      if (a[i][j]) {
        bfs(i, j);
        ans = max(ans, cnt);
      }
    }
  }
  printf("%d", ans);
}
