#include <bits/stdc++.h>
int H, W;
int maze[21][21];
int solve(int max) {
  for (;;) {
    int done = 1;
    for (int h = 0; h < H; h++) {
      for (int w = 0; w < W; w++) {
        int d = maze[h][w] + 1;
        if (maze[h][w] == 999999) continue;
        int n = 0;
        if (h > 0) {
          if (maze[h - 1][w] != 999999) {
            if (maze[h - 1][w] > d) {
              maze[h - 1][w] = d;
              ++n;
            }
          }
        }
        if (h < (H - 1)) {
          if (maze[h + 1][w] != 999999) {
            if (maze[h + 1][w] > d) {
              maze[h + 1][w] = d;
              ++n;
            }
          }
        }
        if (w > 0) {
          if (maze[h][w - 1] != 999999) {
            if (maze[h][w - 1] > d) {
              maze[h][w - 1] = d;
              ++n;
            }
          }
        }
        if (w < (W - 1)) {
          if (maze[h][w + 1] != 999999) {
            if (maze[h][w + 1] > d) {
              maze[h][w + 1] = d;
              ++n;
            }
          }
        }
        if (n > 0) {
          done = 0;
          if (d > max) max = d;
        }
      }
    }
    if (done) return max;
  }
}
int main(int argc, char **argv) {
  scanf("%d%d", &H, &W);
  int sh, sw;
  for (int h = 0; h < H; h++) {
    char line[21];
    scanf("%s", line);
    for (int w = 0; w < W; w++) {
      char ch = line[w];
      if (ch == '#') {
        maze[h][w] = 999999;
      } else {
        sh = h;
        sw = w;
        maze[h][w] = 99999;
      }
    }
  }
  int max = 0;
retry:
  maze[sh][sw] = 0;
  max = solve(max);
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      int d = maze[h][w];
      if (d == 99999) {
        sh = h;
        sw = w;
        goto retry;
      }
      if (d == max) {
        sh = h;
        sw = w;
      }
    }
  }
next:
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      int d = maze[h][w];
      if (d != 999999) maze[h][w] = 99999;
    }
  }
  maze[sh][sw] = 0;
  max = solve(0);
  printf("%d\n", max);
  return 0;
}
