#include <bits/stdc++.h>
using namespace std;
const int N = 805;
char s[N][N];
bool v[N][N];
int n, m, K, ans;
void dfs(int x, int y) {
  if (v[x][y]) return;
  v[x][y] = true;
  ans = min(ans, min(min(x - 1, n - x), min(y - 1, m - y)));
  for (int dx : {-1, 1})
    for (int dy : {-1, 1})
      if (s[x + dx][y + dy] == '.') dfs(x + dx, y + dy);
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  ans = min(n, m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] == 'S') {
        dfs(i, j);
        break;
      }
  printf("%d\n", 1 + (ans + K - 1) / K);
  return 0;
}
