#include <bits/stdc++.h>
using namespace std;
char a[801][801];
int b[801][801];
int x, y, k;
int z;
int c, d;
void tansaku(int xx, int yy, int q) {
  if (q <= 0) return;
  if (xx > 0) {
    if (a[xx - 1][yy] == '.' || q > b[xx - 1][yy]) {
      a[xx - 1][yy] = 'V';
      b[xx - 1][yy] = q;
      tansaku(xx - 1, yy, q - 1);
    }
  }
  if (xx < x - 1) {
    if (a[xx + 1][yy] == '.' || q > b[xx + 1][yy]) {
      a[xx + 1][yy] = 'V';
      b[xx + 1][yy] = q;
      tansaku(xx + 1, yy, q - 1);
    }
  }
  if (yy > 0) {
    if (a[xx][yy - 1] == '.' || q > b[xx][yy - 1]) {
      a[xx][yy - 1] = 'V';
      b[xx][yy - 1] = q;
      tansaku(xx, yy - 1, q - 1);
    }
  }
  if (yy < y - 1) {
    if (a[xx][yy + 1] == '.' || q > b[xx][yy + 1]) {
      a[xx][yy + 1] = 'V';
      b[xx][yy + 1] = q;
      tansaku(xx, yy + 1, q - 1);
    }
  }
  return;
}
int main(void) {
  scanf("%d %d %d", &x, &y, &k);
  for (int i = 0; i < x; i++) {
    scanf("%s", a[i]);
  }
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      b[i][j] = 1000000;
    }
  }
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      if (a[i][j] == 'S') {
        a[i][j] = 'V';
        b[i][j] = k + 1;
        tansaku(i, j, k);
      }
    }
  }
  d = 1000;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      if (a[i][j] == 'V') {
        c = i;
        if (x - i - 1 < c) c = x - i - 1;
        if (j < c) c = j;
        if (y - j - 1 < c) c = y - j - 1;
        if (c < d) d = c;
      }
    }
  }
  if (d == 0)
    z = 1;
  else {
    z = (d - 1) / k;
    z = z + 2;
  }
  printf("%d\n", z);
  return 0;
}
