#include <bits/stdc++.h>
int h, w, k;
int min = 10000;
char build[810][810];
void dfs(int x, int y) {
  build[x][y] = '#';
  min = std::min(min, std::min(x - 1, std::min(w - x, std::min(y - 1, h - y))));
  for (int dx = -1; dx <= 1; dx++) {
    for (int dy = -1; dy <= 1; dy++) {
      int nx = x + dx, ny = y + dy;
      if (1 <= nx && nx <= h && 1 <= ny && ny <= w && build[nx][ny] == '.')
        dfs(nx, ny);
    }
  }
}
int main() {
  std::cin >> h >> w >> k;
  char a;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      std::cin >> a;
      build[i][j] = a;
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (build[i][j] == '.') {
        dfs(i, j);
      }
    }
  }
  std::cout << min << std::endl;
}
