#include <bits/stdc++.h>
typedef struct {
  intmax_t x;
  intmax_t y;
} COORDINATE;
typedef struct {
  intmax_t writeidx;
  intmax_t readidx;
  intmax_t count;
  COORDINATE buff[4096];
} FIFO;
void fifo_init(FIFO *fifo) {
  fifo->writeidx = 0;
  fifo->readidx = 0;
  fifo->count = 0;
}
void fifo_enqueue(FIFO *fifo, const COORDINATE *v) {
  intmax_t i;
  if (v == NULL) return;
  if (fifo->count < 4096) {
    i = fifo->writeidx;
    fifo->count++;
    fifo->buff[i] = *v;
    fifo->writeidx = (i + 1) % 4096;
  }
}
int64_t fifo_dequeue(FIFO *fifo, COORDINATE *r) {
  intmax_t i;
  if (r == NULL) return 1;
  if (fifo->count == 0) return 1;
  i = fifo->readidx;
  *r = fifo->buff[i];
  fifo->count--;
  fifo->readidx = (i + 1) % 4096;
  return 0;
}
int main(int argc, char const *argv[]) {
  intmax_t H, W;
  char S[50][51];
  intmax_t ans = 0;
  scanf("%jd%jd", &H, &W);
  for (int i = 1; i <= H; i++) {
    scanf("%s", &S[i][1]);
  }
  for (size_t sx = 1; sx <= W; sx++) {
    for (size_t sy = 1; sy <= H; sy++) {
      char s[50][51];
      intmax_t a[50][50] = {0};
      FIFO fifo;
      COORDINATE xy[5];
      fifo_init(&fifo);
      for (int i = 1; i <= H; i++) {
        strcpy(&s[i][1], &S[i][1]);
      }
      if (s[sy][sx - 1] == '#') continue;
      xy[0].x = sx;
      xy[0].y = sy;
      s[xy[0].y][xy[0].x] = ',';
      fifo_enqueue(&fifo, &xy[0]);
      while (fifo_dequeue(&fifo, &xy[0]) == 0) {
        xy[1].x = xy[0].x - 1;
        xy[1].y = xy[0].y;
        xy[2].x = xy[0].x;
        xy[2].y = xy[0].y - 1;
        xy[3].x = xy[0].x + 1;
        xy[3].y = xy[0].y;
        xy[4].x = xy[0].x;
        xy[4].y = xy[0].y + 1;
        for (int i = 1; i < 5; i++) {
          if (s[xy[i].y][xy[i].x] == '.') {
            a[xy[i].y][xy[i].x] = a[xy[0].y][xy[0].x] + 1;
            s[xy[i].y][xy[i].x] = ',';
            fifo_enqueue(&fifo, &xy[i]);
          }
        }
      }
      for (size_t gy = 1; gy <= H; gy++) {
        for (size_t gx = 1; gx <= W; gx++) {
          if (a[gy][gx] > ans) {
            ans = a[gy][gx];
          }
        }
      }
    }
  }
  printf("%jd\n", ans);
}
