#include <bits/stdc++.h>
using namespace std;
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, -1, 0, 1};
int main() {
  int H, W;
  cin >> H >> W;
  char array[20][20];
  int Count = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> array[i][j];
    }
  }
  char str[] = "#";
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (strcmp(&array[i][j], str) == 0) {
        continue;
      }
      vector<vector<int>> dist(H, vector<int>(W, (1001001001)));
      queue<pair<int, int>> q;
      auto update = [&](int i, int j, int x) {
        if (dist[i][j] != (1001001001)) {
          return;
        }
        dist[i][j] = x;
        q.push(pair<int, int>(i, j));
      };
      update(i, j, 0);
      while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        for (int k = 0; k < 4; k++) {
          int ni = i + di[k];
          int nj = j + dj[k];
          if (ni < 0 || ni > H || nj < 0 || nj > W) {
            continue;
          }
          if (strcmp(&array[ni][nj], "#") == 0) {
            continue;
          }
          update(ni, nj, dist[i][j] + 1);
        }
      }
    }
  }
  return 0;
}
