#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * t;
}
int n, m;
int mp[805][805];
int Sx, Sy, k;
char s[805];
bool vis[805][805];
int count(int x, int y) {
  int f1 = (x + k - 2) / k, f2 = (n - x + k - 1) / k;
  int f3 = (y + k - 2) / k, f4 = (m - y + k - 1) / k;
  return min(min(f1, f2), min(f3, f4));
}
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
void bfs() {
  queue<pair<int, int> > q;
  q.push(make_pair(Sx, Sy));
  int ans = n + m;
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    ans = min(ans, count(now.first, now.second));
    for (int d = 0; d < 4; d++) {
      int nx = now.first + dx[d], ny = now.second + dy[d];
      if (nx < 1 || ny < 1 || nx > n || ny > m || mp[nx][ny] || vis[nx][ny])
        continue;
      vis[nx][ny] = true;
      q.push(make_pair(nx, ny));
    }
  }
  printf("%d\n", ans + 1);
}
int main() {
  n = read();
  m = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++)
      if (s[j] == '.')
        mp[i][j] = 0;
      else if (s[j] == '#')
        mp[i][j] = 1;
      else
        Sx = i, Sy = j;
  }
  bfs();
}
