#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx")
int path[25][25];
int map[25][25];
int x[500];
int y[500];
int x2[500];
int y2[500];
int main(void) {
  int h, w, i, j, k, l, m, mx = 0;
  char buf[50];
  scanf("%d %d", &h, &w);
  for ((i) = 0; (i) < (int)(h); (i)++) {
    scanf("%s", &buf);
    for ((j) = 0; (j) < (int)(w); (j)++) map[i + 1][j + 1] = buf[j];
  }
  for ((i) = 0; (i) < (int)(h + 2); (i)++)
    for ((j) = 0; (j) < (int)(w + 2); (j)++)
      if (i == 0 || j == 0 || i == h + 1 || j == w + 1) map[i][j] = '#';
  for ((i) = 0; (i) < (int)(h + 2); (i)++) {
    for ((j) = 0; (j) < (int)(w + 2); (j)++) {
      if (map[i][j] == '#') continue;
      for ((k) = 0; (k) < (int)(h + 2); (k)++)
        for ((l) = 0; (l) < (int)(w + 2); (l)++) path[k][l] = 1000;
      int flg = 0;
      int lng = 0;
      int cue = 1;
      int cue2 = 0;
      x[0] = i;
      y[0] = j;
      path[i][j] = 0;
      while (cue != 0) {
        for ((k) = 0; (k) < (int)(cue); (k)++) {
          int c = path[x[k]][y[k]];
          int u = path[x[k] - 1][y[k]];
          int d = path[x[k] + 1][y[k]];
          int l = path[x[k]][y[k] - 1];
          int r = path[x[k]][y[k] + 1];
          int mc = map[x[k]][y[k]];
          int mu = map[x[k] - 1][y[k]];
          int md = map[x[k] + 1][y[k]];
          int ml = map[x[k]][y[k] - 1];
          int mr = map[x[k]][y[k] + 1];
          if (mu != '#') {
            if (c + 1 < u) {
              path[x[k] - 1][y[k]] = c + 1;
              x2[cue2] = x[k] - 1;
              y2[cue2] = y[k];
              cue2++;
            }
          }
          if (md != '#') {
            if (c + 1 < d) {
              path[x[k] + 1][y[k]] = c + 1;
              x2[cue2] = x[k] + 1;
              y2[cue2] = y[k];
              cue2++;
            }
          }
          if (ml != '#') {
            if (c + 1 < l) {
              path[x[k]][y[k] - 1] = c + 1;
              x2[cue2] = x[k];
              y2[cue2] = y[k] - 1;
              cue2++;
            }
          }
          if (mr != '#') {
            if (c + 1 < r) {
              path[x[k]][y[k] + 1] = c + 1;
              x2[cue2] = x[k];
              y2[cue2] = y[k] + 1;
              cue2++;
            }
          }
        }
        for ((k) = 0; (k) < (int)(cue2); (k)++) {
          x[k] = x2[k];
          y[k] = y2[k];
        }
        cue = cue2;
        cue2 = 0;
      }
      for ((k) = 0; (k) < (int)(h + 2); (k)++)
        for ((l) = 0; (l) < (int)(w + 2); (l)++)
          mx = ((mx) > (path[k][l] * (map[k][l] == '.'))
                    ? (mx)
                    : (path[k][l] * (map[k][l] == '.')));
    }
  }
  printf("%d", mx);
  return 0;
}
