#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> s;
  string c, l, r, u, d;
  int h, w, k, i, j, p, q, ln = 0, rn = 0, un = 0, dn = 0, ls = 0, rs = 0,
                           us = 0, ds = 0;
  cin >> h >> w >> k;
  for (i = 0; i < h; i++) {
    cin >> c;
    s.push_back(c);
    p = c.find("S");
    if (p != -1) {
      q = p;
      l = c.substr(0, q);
      r = c.substr(q + 1);
      u = d = "";
      for (j = 0; j < i; j++) u += s[j][q];
    }
  }
  for (j = 0; j < h; j++) d += s[j][q];
  d = d.substr(u.size() + 1);
  for (i = 0; i < l.size(); i++)
    if (l[i] == '#') ln++;
  ls = ln / k;
  if (ln % k == 1) ls++;
  ls += l.size() / k;
  if (l.size() % k == 1) ls++;
  for (i = 0; i < r.size(); i++)
    if (r[i] == '#') rn++;
  rs = rn / k;
  if (rn % k == 1) rs++;
  rs += r.size() / k;
  if (r.size() % k == 1) rs++;
  for (i = 0; i < u.size(); i++)
    if (u[i] == '#') un++;
  us = un / k;
  if (un % k == 1) us++;
  us += u.size() / k;
  if (u.size() % k == 1) us++;
  for (i = 0; i < d.size(); i++)
    if (d[i] == '#') dn++;
  ds = dn / k;
  if (dn % k == 1) ds++;
  ds += d.size() / k;
  if (d.size() % k == 1) ds++;
  cout << min(min(ls, rs), min(us, ds)) << endl;
  return 0;
}
