#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
long long ans = 0;
char A[800][800];
int up, down, Left, Right;
int um, dm, Lmm, Rmm;
int main() {
  int h, w, k;
  int sx, sy;
  cin >> h >> w >> k;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      cin >> A[i][j];
      if (A[i][j] == 'S') {
        sx = j, sy = i;
      }
    }
  up = sy / k, down = (h - sy) / k, Left = sx / k, Right = (w - sx) / k;
  for (int i = 0; i < max(h, w); i++) {
    if (sy >= i) {
      if (A[sy - i][sx] == '#') um++;
    }
    if (h - sy >= i) {
      if (A[h - sy - i][sx] == '#') dm++;
    }
    if (sx >= i) {
      if (A[sy][sx - i] == '#') Lmm++;
    }
    if (w - sx >= i) {
      if (A[sy][w - sx - i] == '#') Rmm++;
    }
  }
  um = um / k + !!(um % k);
  dm = dm / k + !!(dm % k);
  Lmm = Lmm / k + !!(Lmm % k);
  Rmm = Rmm / k + !!(Rmm % k);
  up = max(up, um);
  down = max(down, dm);
  Left = max(Left, Lmm);
  Right = max(Right, Rmm);
  int move = min(min(up, down), min(Left, Right));
  cout << move + 1 << endl;
  return 0;
}
