#include <bits/stdc++.h>
int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  int field[22][22] = {0};
  for (int i = 0; i < h; i++) {
    char s[22];
    scanf("%s", s);
    for (int j = 0; j < w; j++)
      if (s[j] == '.') field[i + 1][j + 1] = 1;
  }
  int ans = 0;
  for (int sh = 1; sh <= h; sh++)
    for (int sw = 1; sw <= w; sw++) {
      if (!field[sh][sw]) continue;
      for (int gh = 1; gh <= h; gh++)
        for (int gw = 1; gw <= w; gw++) {
          if (((sh - gh) < 0 ? -(sh - gh) : (sh - gh)) +
                  ((sw - gw) < 0 ? -(sw - gw) : (sw - gw)) <=
              1)
            continue;
          int table[22][22] = {0}, nowh, noww;
          int queue[500][2], front = 0, rear = 0;
          queue[rear][0] = sh, queue[rear][1] = sw, rear++;
          while (front != rear) {
            nowh = queue[front][0], noww = queue[front][1], front++;
            for (int s = -1; s <= 1; s += 2) {
              if (field[nowh + s][noww] && !table[nowh + s][noww]) {
                table[nowh + s][noww] = table[nowh][noww] + 1;
                queue[rear][0] = nowh + s, queue[rear][1] = noww, rear++;
              }
              if (field[nowh][noww + s] && !table[nowh][noww + s]) {
                table[nowh][noww + s] = table[nowh][noww] + 1;
                queue[rear][0] = nowh, queue[rear][1] = noww + s, rear++;
              }
            }
          }
          ans = ans > table[gh][gw] ? ans : table[gh][gw];
        }
    }
  printf("%d\n", ans);
  return 0;
}
