#include <bits/stdc++.h>
using namespace std;
int solve(int H, int W, int K, vector<string>& a) {
  vector<vector<int>> d(H, vector<int>(W));
  for (int i = 0, j = H - 1; i <= j; ++i, --j) {
    int k = (i + K - 1) / K;
    for (int c = 0; c < (W); ++c) d[i][c] = d[j][c] = k;
  }
  for (int i = 0, j = W - 1; i <= j; ++i, --j) {
    int k = (i + K - 1) / K;
    for (int r = 0; r < (H); ++r) {
      d[r][i] = min(d[r][i], k);
      d[r][j] = min(d[r][j], k);
    }
  }
  int best = INT_MAX;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) {
      if (a[i][j] == 'S' || a[i][j] == '.') best = min(best, d[i][j]);
    }
  return 1 + best;
}
int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> a(H);
  for (int i = 0; i < (H); ++i) cin >> a[i];
  cout << solve(H, W, K, a) << endl;
  return 0;
}
