#include <bits/stdc++.h>
int main() {
  int H, W;
  scanf("%d %d", &H, &W) + 1;
  int M[20][20];
  int Mt[20][20];
  char tmp;
  for (int y = 0; y < H; y++) {
    scanf("%c", &tmp) + 1;
    for (int x = 0; x < W; x++) {
      scanf("%c", &tmp) + 1;
      M[y][x] = (tmp == '#') ? -2 : -1;
    }
  }
  int ans = 0;
  for (int x = 0; x < W; x++) {
    for (int y = 0; y < H; y++) {
      if (M[y][x] == -2) break;
      memcpy(Mt, M, sizeof M);
      Mt[y][x] = 0;
      bool henka;
      int cnt = 0;
      while (1) {
        henka = 0;
        for (int x = 0; x < W; x++) {
          for (int y = 0; y < H; y++) {
            if (Mt[y][x] == cnt) {
              if (x != 0 && Mt[y][x - 1] == -1) {
                Mt[y][x - 1] = cnt + 1;
                henka = 1;
              }
              if (y != 0 && Mt[y - 1][x] == -1) {
                Mt[y - 1][x] = cnt + 1;
                henka = 1;
              }
              if (x != W - 1 && Mt[y][x + 1] == -1) {
                Mt[y][x + 1] = cnt + 1;
                henka = 1;
              }
              if (y != H - 1 && Mt[y + 1][x] == -1) {
                Mt[y + 1][x] = cnt + 1;
                henka = 1;
              }
            }
          }
        }
        if (!henka) break;
        cnt++;
      }
      if (cnt > ans) ans = cnt;
    }
  }
  printf("%d\n", ans);
  return 0;
}
