#include <bits/stdc++.h>
int main() {
  long long h, w, k, sx, sy;
  std::cin >> h >> w >> k;
  std::vector<std::string> v(h);
  for (long long i = 0; i < h; i++) {
    std::cin >> v[i];
    auto pos = std::find(v[i].begin(), v[i].end(), 'S');
    if (pos != v[i].end()) {
      sx = i;
      sy = pos - v[i].begin();
    }
  }
  long long ans = 1000000000000;
  ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * sx / k)));
  ans =
      std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - sx - 1) / k)));
  ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * sy / k)));
  ans =
      std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - sy - 1) / k)));
  std::cout << ans + 1 << std::endl;
  return 0;
}
