#include <bits/stdc++.h>
const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int H, W;
char S[32][32];
int cost[512][512];
int main(void) {
  int i, j, k;
  int answer = 0;
  if (scanf("%d%d", &H, &W) != 2) return 1;
  for (i = 0; i < H; i++) {
    if (scanf("%31s", S[i]) != 1) return 1;
  }
  for (i = 0; i < H * W; i++) {
    for (j = 0; j < H * W; j++) {
      cost[i][j] = 999999999;
    }
    cost[i][j] = 0;
  }
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        for (k = 0; k < 4; k++) {
          int ii = i + d[k][0], jj = j + d[k][1];
          if (0 <= ii && ii < H && 0 <= jj && jj < W && S[ii][jj] == '.') {
            cost[i * W + j][ii * W + jj] = 1;
          }
        }
      }
    }
  }
  for (k = 0; k < H * W; k++) {
    for (i = 0; i < H * W; i++) {
      for (j = 0; j < H * W; j++) {
        if (cost[i][j] > cost[i][k] + cost[k][j]) {
          cost[i][j] = cost[i][k] + cost[k][j];
        }
      }
    }
  }
  for (i = 0; i < H * W; i++) {
    for (j = 0; j < H * W; j++) {
      if (S[i / W][i % W] == '.' && S[j / W][j % W] == '.') {
        if (cost[i][j] > answer && cost[i][j] < 999999999) answer = cost[i][j];
      }
    }
  }
  printf("%d\n", answer);
  return 0;
}
