#include <bits/stdc++.h>
int H, W;
int maze[21][21];
int bfs(int sh, int sw) {
  int log[20 * 20] = {0};
  int queue[20 * 20] = {0};
  int qidx, qptr = 0;
  int dh[4] = {1, -1, 0, 0};
  int dw[4] = {0, 0, 1, -1};
  queue[0] = sh * W + sw;
  log[queue[0]] = 1;
  qidx = 1;
  int n;
  while (qidx >= qptr) {
    int pop = queue[qptr];
    ++qptr;
    n = log[pop];
    int h = pop / W;
    int w = pop % W;
    for (int i = 0; i < 4; i++) {
      int hh = h + dh[i];
      int ww = w + dw[i];
      if (hh < 0 || hh >= H) continue;
      if (ww < 0 || ww >= W) continue;
      if (maze[hh][ww] == 999999) continue;
      int pp = hh * W + ww;
      if (log[pp]) continue;
      queue[++qidx] = pp;
      log[pp] = n + 1;
    }
  }
  return n;
}
int main(int argc, char **argv) {
  scanf("%d%d", &H, &W);
  int sh, sw;
  for (int h = 0; h < H; h++) {
    char line[21];
    scanf("%s", line);
    for (int w = 0; w < W; w++) {
      char ch = line[w];
      if (ch == '#') maze[h][w] = 999999;
    }
  }
  int max = 0;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (maze[h][w] == 999999) continue;
      int dis = bfs(h, w);
      if (dis > max) max = dis;
    }
  }
  printf("%d\n", max);
  return 0;
}
