#include <bits/stdc++.h>
using namespace std;
int h, w, k;
string s[810];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w >> k;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int sx, sy;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  int to1 = sx, to2 = sy, to3 = h - sx - 1, to4 = w - sy - 1,
      mto = min(to1, min(to2, min(to3, to4)));
  string v;
  if (mto == to1) {
    int cx = sx, cy = sy;
    while (cx >= 0 && cy >= 0 && cx < h && cy < w) {
      v.push_back(s[cx][cy]);
      cx--;
    }
  } else if (mto == to2) {
    int cx = sx, cy = sy;
    while (cx >= 0 && cy >= 0 && cx < h && cy < w) {
      v.push_back(s[cx][cy]);
      cy--;
    }
  } else if (mto == to3) {
    int cx = sx, cy = sy;
    while (cx >= 0 && cy >= 0 && cx < h && cy < w) {
      v.push_back(s[cx][cy]);
      cx++;
    }
  } else {
    int cx = sx, cy = sy;
    while (cx >= 0 && cy >= 0 && cx < h && cy < w) {
      v.push_back(s[cx][cy]);
      cy++;
    }
  }
  int ans = 0;
  if (v[0] == 'S') v[0] = '.';
  int cur = 0, cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    if (cnt >= k || cur >= k) {
      ans++;
      cur = 0;
      cnt = 0;
    }
    if (v[i] == '.') {
      if (cnt) {
        ans++;
        cur = 0;
        cnt = 0;
      } else {
        cur++;
      }
    }
    if (v[i] == '#') cnt++;
  }
  cout << ans + 1 << endl;
  return 0;
}
