#include <bits/stdc++.h>
inline long long ceil(long long a, long long b) {
  return (a % b ? a / b + 1 : a / b);
}
signed main() {
  long long h, w, k;
  std::cin >> h >> w >> k;
  std::vector<std::string> g(h);
  for (long long i = 0; i < (h); i++) std::cin >> g[i];
  std::pair<long long, long long> spos;
  for (long long i = 0; i < (h); i++)
    for (long long j = 0; j < (w); j++)
      if (g[i][j] == 'S') spos = {i, j};
  long long min = h;
  std::vector<std::vector<long long> > went(h,
                                            std::vector<long long>(w, false));
  std::queue<std::pair<std::pair<long long, long long>, long long> > que;
  que.emplace(spos, 0);
  while (!que.empty()) {
    auto c = que.front();
    que.pop();
    long long x = c.first.first;
    long long y = c.first.second;
    long long d = c.second;
    went[x][y] = true;
    if (d <= k) min = std::min({min, x, y, h - x - 1, w - y - 1});
    for (long long dx = -1; dx <= 1; dx++) {
      for (long long dy = -1; dy <= 1; dy++) {
        if (dx * dy == 0 && x + dx >= 0 && x + dx < h && y + dy >= 0 &&
            y + dy < w && went[x + dx][y + dy] == 0 &&
            g[x + dx][y + dy] == '.') {
          que.emplace(std::make_pair(x + dx, y + dy), d + 1);
        }
      }
    }
  }
  std::cout << (ceil(min, k) + 1) << '\n';
  return 0;
}
