#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
char a[N][N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  int sx, sy;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        sx = i;
        sy = j;
        a[i][j] = '.';
      }
    }
  }
  int ans = 1000;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (abs(sx - i) + abs(sy - j) <= k && a[i][j] == '.') {
        int len = min(i, h - i - 1);
        len = min(len, min(j, w - j));
        ans = min(ans, (len + k - 1) / k + 1);
      }
    }
  }
  cout << ans;
  return 0;
}
