#include <bits/stdc++.h>
using namespace std;
int H, W;
char S[20][20];
int chk[20][20];
int ans = 0;
int tmp = 0;
queue<int> qx, qy;
void bfs(int x, int y) {
  if (x > 0 && S[x - 1][y] == '.' && chk[x - 1][y] == 1000) {
    qx.push(x - 1);
    qy.push(y);
    chk[x - 1][y] = chk[x][y] + 1;
  }
  if (x < H && S[x + 1][y] == '.' && chk[x + 1][y] == 1000) {
    qx.push(x + 1);
    qy.push(y);
    chk[x + 1][y] = chk[x][y] + 1;
  }
  if (y > 0 && S[x][y - 1] == '.' && chk[x][y - 1] == 1000) {
    qx.push(x);
    qy.push(y - 1);
    chk[x][y - 1] = chk[x][y] + 1;
  }
  if (y < W && S[x][y + 1] == '.' && chk[x][y + 1] == 1000) {
    qx.push(x);
    qy.push(y + 1);
    chk[x][y + 1] = chk[x][y] + 1;
  }
  tmp = max(tmp, chk[x][y]);
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
      chk[i][j] = 1000;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        qx.push(i);
        qy.push(j);
        chk[i][j] = 0;
        while (!qx.empty()) {
          bfs(qx.front(), qy.front());
          qx.pop();
          qy.pop();
        }
        ans = max(ans, tmp);
        tmp = 0;
        for (int l = 0; l < H; l++) {
          for (int m = 0; m < W; m++) {
            chk[l][m] = 1000;
          }
        }
      }
    }
  }
  printf("%d\n", ans);
}
