#include <bits/stdc++.h>
using namespace std;
const int N = 800 + 5, INF = 1e9;
const long long linf = 1e18;
const double eps = 1e-8, pi = acos(-1);
inline int gmin(int &a, int b) {
  if (a > b) a = b;
}
inline long long gmin(long long &a, long long b) {
  if (a > b) a = b;
}
inline int gmax(int &a, int b) {
  if (a < b) a = b;
}
inline long long gmax(long long &a, long long b) {
  if (a < b) a = b;
}
inline void read(long long &x) {
  long long f = 1, t = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  x = t * f;
}
inline long long read(long long &x, long long &y) {
  read(x);
  read(y);
}
inline void read(int &x) {
  int f = 1, t = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  x = t * f;
}
inline int read(int &x, int &y) {
  read(x);
  read(y);
}
inline void read(int &a, int &b, int &c) {
  read(a);
  read(b);
  read(c);
}
inline void read(long long &a, long long &b, long long &c) {
  read(a);
  read(b);
  read(c);
}
inline int read() {
  int x;
  read(x);
  return x;
}
inline void judge() {
  freopen("dato.in", "r", stdin);
  freopen("dato.out", "w", stdout);
}
char s[N][N];
int qx[N * N], qy[N * N], dis[N][N], n, m, k, vis[N][N];
const int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int main() {
  read(n, m, k);
  int res = INF;
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++) dis[i][j] = INF, vis[i][j] = 0;
  for (int i = (1); i <= (n); i++) {
    scanf("%s", s[i] + 1);
    for (int j = (1); j <= (m); j++)
      if (s[i][j] == 'S') dis[qx[1] = i][qy[1] = j] = 0, vis[i][j] = 1;
  }
  int t = 1;
  for (int h = (1); h <= (t); h++) {
    int oo = min(min(qx[h] - 1, n - qx[h]), min(qy[h] - 1, m - qy[h]));
    gmin(res, (oo - 1 + k) / k);
    if (dis[qx[h]][qy[h]] < k)
      for (int j = (0); j < (4); j++) {
        int nx = qx[h] + dx[j], ny = qy[h] + dy[j];
        if (s[nx][ny] == '.' && !vis[nx][ny])
          qx[++t] = nx, qy[t] = ny, vis[nx][ny] = 1;
      }
  }
  cout << res + 1 << endl;
}
