#include <bits/stdc++.h>
char map[22][22];
int func(int y, int x) {
  char test[22][22];
  int ans[22][22];
  for (int i = 0; i < 22; i++) {
    for (int j = 0; j < 22; j++) {
      test[i][j] = map[i][j];
      ans[i][j] = 0;
    }
  }
  int ys[1000], xs[1000], l = 0, p = 0;
  ys[0] = y;
  xs[0] = x;
  l++;
  test[y][x] = '#';
  ans[y][x] = 0;
  while (p < l) {
    int ny = ys[p], nx = xs[p];
    if (test[ny - 1][nx] == '.') {
      ys[l] = ny - 1;
      xs[l] = nx;
      l++;
      test[ny - 1][nx] = '#';
      ans[ny - 1][nx] = ans[ny][nx] + 1;
    }
    if (test[ny][nx + 1] == '.') {
      ys[l] = ny;
      xs[l] = nx + 1;
      l++;
      test[ny][nx + 1] = '#';
      ans[ny][nx + 1] = ans[ny][nx] + 1;
    }
    if (test[ny + 1][nx] == '.') {
      ys[l] = ny + 1;
      xs[l] = nx;
      l++;
      test[ny + 1][nx] = '#';
      ans[ny + 1][nx] = ans[ny][nx] + 1;
    }
    if (test[ny][nx - 1] == '.') {
      ys[l] = ny;
      xs[l] = nx - 1;
      l++;
      test[ny][nx - 1] = '#';
      ans[ny - 1][nx] = ans[ny][nx] + 1;
    }
    p++;
  }
  int max = 0;
  for (int i = 0; i < 22; i++) {
    for (int j = 0; j < 22; j++) {
      if (max < ans[i][j] && map[i][j] == '.') {
        max = ans[i][j];
      }
    }
  }
  return max;
}
int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  for (int i = 0; i < 22; i++) {
    for (int j = 0; j < 22; j++) {
      map[i][j] = '#';
    }
  }
  for (int i = 1; i < h + 1; i++) {
    char s[w + 1];
    scanf("%s", s);
    for (int j = 0; j < w; j++) {
      map[i][j + 1] = s[j];
    }
  }
  int ans = 0;
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      if (map[i][j] == '.') {
        int buf = func(i, j);
        if (ans < buf) {
          ans = buf;
        }
      }
    }
  }
  printf("%d", ans);
  return 0;
}
