#include <bits/stdc++.h>
int h, w;
char maze[21][21];
int dist[20][20];
int qx[100000], qy[100000], head, tail;
int vx[4] = {0, 1, 0, -1};
int vy[4] = {1, 0, -1, 0};
void bfs(int stx, int sty) {
  dist[sty][stx] = 0;
  head = tail = 0;
  qx[tail] = stx;
  qy[tail] = sty;
  tail++;
  while (head != tail) {
    for (int i = 0; i < 4; i++) {
      int nx = qx[head] + vx[i];
      int ny = qy[head] + vy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny <= h && dist[ny][nx] == -1 &&
          maze[ny][nx] == '.') {
        dist[ny][nx] = dist[qy[head]][qx[head]] + 1;
        qx[tail] = nx;
        qy[tail] = ny;
        tail++;
      }
    }
    head++;
  }
}
int main() {
  int max = 0, cnt = 0;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", maze[i]);
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          dist[k][l] = -1;
        }
      }
      bfs(j, i);
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          cnt = dist[k][l];
          if (cnt > max) {
            max = cnt;
          }
        }
      }
    }
  }
  printf("%d\n", max);
  return 0;
}
