#include <bits/stdc++.h>
char wa[801][801];
int K, H, W, x, y;
int x1, x2, y1, y2;
void xiazou(int bu) {
  if (bu == K) return;
  if (wa[x + 1][y] == '.' || wa[x + 1][y] == 's' || wa[x + 1][y] == 'S') {
    x += 1;
    bu += 1;
    if (x > x2) x2 = x;
    if (x == H) {
      return;
    }
    wa[x - 1][y] = '#';
    xiazou(bu);
    x -= 1;
    bu -= 1;
    wa[x][y] = '.';
  }
  if (wa[x - 1][y] == '.' || wa[x - 1][y] == 's' || wa[x - 1][y] == 'S') {
    x -= 1;
    bu += 1;
    if (x < x1) x1 = x;
    if (x == 1) {
      return;
    }
    wa[x + 1][y] = '#';
    xiazou(bu);
    x += 1;
    bu -= 1;
    wa[x][y] = '.';
  }
  if (wa[x][y + 1] == '.' || wa[x][y + 1] == 's' || wa[x][y + 1] == 'S') {
    y += 1;
    bu += 1;
    if (y > y2) y2 = y;
    if (y == W) {
      return;
    }
    wa[x][y - 1] = '#';
    xiazou(bu);
    y -= 1;
    bu -= 1;
    wa[x][y] = '.';
  }
  if (wa[x][y - 1] == '.' || wa[x][y - 1] == 's' || wa[x][y - 1] == 'S') {
    y -= 1;
    bu += 1;
    if (y < y1) y1 = y;
    if (y == 1) {
      return;
    }
    wa[x][y + 1] = '#';
    xiazou(bu);
    y += 1;
    bu -= 1;
    wa[x][y] = '.';
  }
  return;
}
int main(void) {
  int i, a, mid;
  scanf("%d%d%d", &H, &W, &K);
  getchar();
  for (i = 1; i <= W; i++) {
    for (a = 1; a <= H; a++) {
      scanf("%c", &wa[a][i]);
      if (wa[a][i] == 's' || wa[a][i] == 'S') {
        x = a;
        y = i;
        x1 = x;
        x2 = x;
        y1 = y;
        y2 = y;
      }
    }
    getchar();
  }
  xiazou(0);
  if (x2 == H || x1 == 1 || y2 == W || y1 == 1) {
    printf("1");
    return 0;
  }
  x1 -= 1;
  x2 = H - x2;
  y1 -= 1;
  y2 = W - y2;
  mid = x1 < x2 ? x1 : x2;
  if (mid > (y1 < y2 ? y1 : y2)) mid = y1 < y2 ? y1 : y2;
  if (mid % K == 0)
    mid = mid / K + 1;
  else
    mid = mid / K + 2;
  printf("%d", mid);
  return 0;
}
