#include <bits/stdc++.h>
int h, w;
int minl(int maze[21][21], int x1, int y1, int x2, int y2, int mi) {
  int i;
  int xx;
  int yy;
  int mm;
  int mmm;
  if (x1 == x2) {
    if (y1 + 1 == y2) return 1;
    if (y1 - 1 == y2) return 1;
    if (abs(y1 - y2) > mi) return 1000000;
    if (y1 < y2) {
      for (yy = y1 + 1; yy < y2; yy++) {
        if (maze[x1][yy] == 0) break;
      }
      if (yy == y2) return (y2 - y1);
    } else {
      for (yy = y1 - 1; yy > y2; yy--) {
        if (maze[x1][yy] == 0) break;
      }
      if (yy == y2) return (y1 - y2);
    }
  }
  if (y1 == y2) {
    if (x1 + 1 == x2) return 1;
    if (x1 - 1 == x2) return 1;
    if (abs(x1 - x2) > mi) return 1000000;
    if (x1 < x2) {
      for (xx = x1 + 1; xx < x2; xx++) {
        if (maze[xx][y1] == 0) break;
      }
      if (xx == x2) return (x2 - x1);
    } else {
      for (xx = x1 - 1; xx > x2; xx--) {
        if (maze[xx][y1] == 0) break;
      }
      if (xx == x2) return (x1 - x2);
    }
  }
  maze[x1][y1] = 0;
  mmm = mi;
  if (x1 < w - 1 && maze[x1 + 1][y1] == 1) {
    mm = minl(maze, x1 + 1, y1, x2, y2, mi) + 1;
    if (mm < mmm) {
      mmm = mm;
    }
  }
  if (y1 < h - 1 && maze[x1][y1 + 1] == 1) {
    mm = minl(maze, x1, y1 + 1, x2, y2, mi) + 1;
    if (mm < mmm) {
      mmm = mm;
    }
  }
  if (x1 > 0 && maze[x1 - 1][y1] == 1) {
    mm = minl(maze, x1 - 1, y1, x2, y2, mi) + 1;
    if (mm < mmm) {
      mmm = mm;
    }
  }
  if (y1 > 0 && maze[x1][y1 - 1] == 1) {
    mm = minl(maze, x1, y1 - 1, x2, y2, mi) + 1;
    if (mm < mmm) {
      mmm = mm;
    }
  }
  maze[x1][y1] = 1;
  return mmm;
}
int main(int argc, char *argv[]) {
  int i, j;
  int ii, jj;
  char cc[21];
  int maze[21][21];
  int m, mm;
  scanf("%d %d", &h, &w);
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      maze[i][j] = 0;
    }
  }
  for (i = 0; i < h; i++) {
    scanf("%s", cc);
    for (j = 0; j < w; j++) {
      if (cc[j] == '.') maze[i][j] = 1;
    }
  }
  mm = 0;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (maze[i][j] == 1) {
        for (ii = 0; ii < h; ii++) {
          for (jj = 0; jj < w; jj++) {
            if (i == ii && j == jj) continue;
            if (maze[ii][jj] == 1) {
              m = minl(maze, i, j, ii, jj, 1000000);
              if (m < 1000000 && m > mm) mm = m;
            }
          }
        }
      }
    }
  }
  printf("%d\n", mm);
}
