#include <bits/stdc++.h>
int compare_int(const void *a, const void *b) { return *(int *)b - *(int *)a; }
typedef struct task {
  int x;
  int y;
};
int main() {
  int h, w;
  int s[25][25] = {};
  int i, j;
  int c[25][25];
  int max = 0;
  char in[25];
  int n = 0;
  int t_x[100000];
  int t_y[100000];
  int t_i;
  int x, y;
  int now;
  int c_x, c_y, c_c;
  scanf("%d %d", &h, &w);
  for (i = 0; i < h; i++) {
    scanf("%s", in);
    for (j = 0; j < w; j++) {
      if (in[j] == '.') {
        s[i + 1][j + 1] = 1;
      } else {
        s[i + 1][j + 1] = 0;
      }
    }
  }
  for (y = 1; y < h + 1; y++) {
    for (x = 1; x < w + 1; x++) {
      for (i = 0; i < h + 2; i++) {
        for (j = 0; j < w + 2; j++) {
          if (s[i][j] == 1) {
            c[i][j] = -1;
          } else {
            c[i][j] = 0;
          }
        }
      }
      t_y[0] = y;
      t_x[0] = x;
      t_i = 1;
      if (c[y][x] == -1) {
        continue;
      }
      c[y][x] = 1;
      now = 0;
      while (t_i != now) {
        c_x = t_x[now];
        c_y = t_y[now];
        c_c = c[c_y][c_x];
        if (c[c_y][c_x - 1] == -1) {
          c[c_y][c_x - 1] = c_c + 1;
          t_y[t_i] = c_y;
          t_x[t_i] = c_x - 1;
          t_i++;
        } else if (c[c_y][c_x - 1] != 0) {
          if (c[c_y][c_x - 1] - 1 > c_c) {
            c[c_y][c_x - 1] = c_c + 1;
            t_y[t_i] = c_y;
            t_x[t_i] = c_x - 1;
            t_i++;
          }
        } else {
        }
        if (c[c_y][c_x + 1] == -1) {
          c[c_y][c_x + 1] = c_c + 1;
          t_y[t_i] = c_y;
          t_x[t_i] = c_x + 1;
          t_i++;
        } else if (c[c_y][c_x + 1] != 0) {
          if (c[c_y][c_x + 1] - 1 > c_c) {
            c[c_y][c_x + 1] = c_c + 1;
            t_y[t_i] = c_y;
            t_x[t_i] = c_x + 1;
            t_i++;
          }
        } else {
        }
        if (c[c_y - 1][c_x] == -1) {
          c[c_y - 1][c_x] = c_c + 1;
          t_y[t_i] = c_y - 1;
          t_x[t_i] = c_x;
          t_i++;
        } else if (c[c_y - 1][c_x] != 0) {
          if (c[c_y - 1][c_x] - 1 > c_c) {
            c[c_y - 1][c_x] = c_c + 1;
            t_y[t_i] = c_y - 1;
            t_x[t_i] = c_x;
            t_i++;
          }
        } else {
        }
        if (c[c_y + 1][c_x] == -1) {
          c[c_y + 1][c_x] = c_c + 1;
          t_y[t_i] = c_y + 1;
          t_x[t_i] = c_x;
          t_i++;
        } else if (c[c_y + 1][c_x] != 0) {
          if (c[c_y + 1][c_x] - 1 > c_c) {
            c[c_y + 1][c_x] = c_c + 1;
            t_y[t_i] = c_y + 1;
            t_x[t_i] = c_x;
            t_i++;
          }
        } else {
        }
        for (i = 1; i < h + 1; i++) {
          for (j = 1; j < w + 1; j++) {
            if (max < c[i][j]) {
              max = c[i][j];
            }
          }
        }
        now++;
      }
    }
  }
  printf("%d\n", max - 1);
  return 0;
}
