#include <bits/stdc++.h>
using namespace std;
long long h, w, k;
vector<string> a;
long long sx, sy;
long long mind = 10000000000;
long long near(long long x, long long y) {
  return min({x, y, h - x - 1, w - y - 1});
}
int main() {
  cin >> h >> w >> k;
  a = vector<string>(h);
  for (long long i = 0; i < h; i++) cin >> a[i];
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (a[i][j] == 'S') {
        sx = i;
        sy = j;
        break;
      }
    }
  }
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (a[i][j] != '#' && i - sx + j - sy <= k) {
        mind = min(mind, near(i, j));
      }
    }
  }
  if (mind == 0)
    cout << 1 << endl;
  else
    cout << (mind - 1) / k + 2 << endl;
  return 0;
}
