#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1000000007;
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> a(h);
  deque<tuple<int, int, int>> q;
  vector<vector<bool>> b(h, vector<bool>(w, true));
  int x = 1000;
  for (int i = (0); i < (h); i++) {
    cin >> a[i];
    int p;
    if ((p = a[i].find('S')) != string::npos) {
      q.emplace_back(i, p, 0);
      b[i][p] = false;
      x = min({i, h - i - 1, p, w - p - 1});
    }
  }
  int r, c, n;
  while (!q.empty()) {
    tie(r, c, n) = q.front();
    q.pop_front();
    if (n >= k) {
      continue;
    }
    if (r != 0 && b[r - 1][c] && a[r - 1][c] == '.') {
      q.emplace_back(r - 1, c, n + 1);
      b[r - 1][c] = false;
      x = min({r - 1, h - (r - 1) - 1, c, w - c - 1});
    }
    if (r != h - 1 && b[r + 1][c] && a[r + 1][c] == '.') {
      q.emplace_back(r + 1, c, n + 1);
      b[r + 1][c] = false;
      x = min({r + 1, h - (r + 1) - 1, c, w - c - 1});
    }
    if (c != 0 && b[r][c - 1] && a[r][c - 1] == '.') {
      q.emplace_back(r, c - 1, n + 1);
      b[r][c - 1] = false;
      x = min({r, h - r - 1, c - 1, w - (c - 1) - 1});
    }
    if (c != w - 1 && b[r][c + 1] && a[r][c + 1] == '.') {
      q.emplace_back(r, c + 1, n + 1);
      b[r][c + 1] = false;
      x = min({r, h - r - 1, c + 1, w - (c + 1) - 1});
    }
  }
  cout << (x + k - 1) / k + 1 << endl;
}
