#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long zero = 0;
using P = pair<long long, long long>;
void chmin(long long &a, long long b) {
  if (a > b) a = b;
}
void chmax(long long &a, long long b) {
  if (a < b) a = b;
}
void pmod(long long &a, long long b) { a = (a + b) % MOD; }
void pmod(long long &a, long long b, long long c) { a = (b + c) % MOD; }
void qmod(long long &a, long long b) { a = (a * b) % MOD; }
void qmod(long long &a, long long b, long long c) { a = (b * c) % MOD; }
void ans1(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void ans2(bool x) {
  if (x)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void ans3(bool x) {
  if (x)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}
void ans(bool x, long long y, long long z) {
  if (x)
    cout << y << endl;
  else
    cout << z << endl;
}
void ans(bool x, string y, string z) {
  if (x)
    cout << y << endl;
  else
    cout << z << endl;
}
long long gcd(long long x, long long y) {
  long long r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}
struct z {
  long long x;
  long long y;
  long long l;
};
int main() {
  long long i, j, o;
  long long res = 0, res1 = INF, res2 = -INF, buf = 0;
  bool judge = true;
  long long h, w, k;
  cin >> h >> w >> k;
  long long a[h][w];
  long long buf1, buf2;
  for (i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (j = 0; j < w; j++) {
      if (s[j] == '#')
        a[i][j] = 0;
      else if (s[i] == '.')
        a[i][j] = 1;
      else {
        a[i][j] = 1;
        buf1 = i;
        buf2 = j;
      }
    }
  }
  queue<struct z> p;
  vector<vector<long long>> d(h, vector<long long>(w, 0));
  p.push({buf1, buf2, zero});
  while (!p.empty()) {
    long long x = p.front().x;
    long long y = p.front().y;
    long long l = p.front().l;
    if (l == k + 1) break;
    if (d[x][y] == 0 && a[x][y] == 1) {
      if (x == 0 || x == h - 1 || y == 0 || y == w - 1) {
        res1 = 1;
        break;
      }
      d[x][y] = 1;
      if (x <= h - 2) p.push({x + 1, y, l + 1});
      if (y <= w - 2) p.push({x, y + 1, l + 1});
      if (x >= 1) p.push({x - 1, y, l + 1});
      if (y >= 1) p.push({x, y - 1, l + 1});
      chmin(res1, (min(min(h - 1 - x, x), min(w - 1 - y, y)) + k - 1) / k + 1);
    }
    p.pop();
  }
  cout << res1 << endl;
  return 0;
}
