#include <bits/stdc++.h>
using namespace std;
struct XX {
  int s;
  int e;
  int t;
  int i;
  int sgn;
};
class xxGreater {
 public:
  bool operator()(const XX& riLeft, const XX& riRight) const {
    if ((riLeft.sgn) == (riRight.sgn)) {
      return riLeft.i < riRight.i;
    }
    return (riLeft.sgn) < (riRight.sgn);
  }
};
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  int a[20][20];
  for (int i = 0; i < H; i++) {
    string tmp;
    cin >> tmp;
    for (int j = 0; j < W; j++) {
      if (tmp.substr(j, 1) == "#") {
        a[i][j] = -1;
      } else {
        a[i][j] = 0;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    int f = 0;
    for (int j = 0; j < W; j++) {
      if (a[i][j] == 0) {
        a[i][j] = 1;
        f = 1;
        break;
      }
    }
    if (f == 1) {
      break;
    }
  }
  int ind = 0;
  while (ind <= 4000) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (a[i][j] != 0) {
          continue;
        }
        int tmp = 40000;
        if (i + 1 < H && a[i + 1][j] > 0) {
          tmp = min(tmp, a[i + 1][j]);
        }
        if (i - 1 >= 0 && a[i - 1][j] > 0) {
          tmp = min(tmp, a[i - 1][j]);
        }
        if (j + 1 < W && a[i][j + 1] > 0) {
          tmp = min(tmp, a[i][j + 1]);
        }
        if (j - 1 >= 0 && a[i][j - 1] > 0) {
          tmp = min(tmp, a[i][j - 1]);
        }
        if (tmp < 40000) {
          a[i][j] = tmp + 1;
        }
      }
    }
    ind++;
  }
  int tmpmax = 0;
  int indi, indj;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] > tmpmax) {
        tmpmax = a[i][j];
        indi = i;
        indj = j;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] > 0) {
        a[i][j] = 0;
      }
    }
  }
  a[indi][indj] = 1;
  ind = 0;
  while (ind <= 4000) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (a[i][j] != 0) {
          continue;
        }
        int tmp = 40000;
        if (i + 1 < H && a[i + 1][j] > 0) {
          tmp = min(tmp, a[i + 1][j]);
        }
        if (i - 1 >= 0 && a[i - 1][j] > 0) {
          tmp = min(tmp, a[i - 1][j]);
        }
        if (j + 1 < W && a[i][j + 1] > 0) {
          tmp = min(tmp, a[i][j + 1]);
        }
        if (j - 1 >= 0 && a[i][j - 1] > 0) {
          tmp = min(tmp, a[i][j - 1]);
        }
        if (tmp < 40000) {
          a[i][j] = tmp + 1;
        }
      }
    }
    ind++;
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, a[i][j]);
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
