#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
struct None{};
struct Elm {
  int r, c, p, q, dir;
};
int n, m, a;
vi dr = {1, 0, -1, 0};
vi dc = {0, -1, 0, 1};
vector<vector<vector<vector<vector<bool>>>>> dp;
void dfs(int r, int c, int p, int q, int dir, vector<vector<char>> &g, vector<vector<bool>> &sel) {
  if(dp[r][c][p][q][dir]) return;
  dp[r][c][p][q][dir] = true;
  int nr = r + dr[dir], nc = c + dc[dir];
  if(0 <= nr && nr < n && 0 <= nc && nc < m && g[nr][nc] != '#') {
    bool psel = sel[r][c];
    sel[r][c] = true;
    dfs(nr, nc, p, q, dir, g, sel);
    sel[r][c] = psel;
  }
  if(g[r][c] != 'S' && ((dir%2 && q < a) || (!(dir%2) && p < a))) {
    int ndir = (dir + 3) % 4;
    int nr = r + dr[ndir], nc = c + dc[ndir];
    int np = p + !(dir%2);
    int nq = q + dir%2;
    if(0 <= nr && nr < n && 0 <= nc && nc < m && g[nr][nc] != '#' && !sel[r][c]) {
      bool psel = sel[r][c];
      sel[r][c] = true;
      char prev = g[r][c];
      g[r][c] = '#';
      dfs(nr, nc, np, nq, ndir, g, sel);
      g[r][c] = prev;
      sel[r][c] = psel;
    }
  }
  if(g[r][c] != 'S' && ((dir%2 && p < a) || (!(dir%2) && q < a))) {
    int ndir = (dir + 1) % 4;
    int nr = r + dr[ndir], nc = c + dc[ndir];
    int np = p + dir%2;
    int nq = q + !(dir%2);
    if(0 <= nr && nr < n && 0 <= nc && nc < m && g[nr][nc] != '#' && !sel[r][c]) {
      bool psel = sel[r][c];
      sel[r][c] = true;
      char prev = g[r][c];
      g[r][c] = '#';
      dfs(nr, nc, np, nq, ndir, g, sel);
      g[r][c] = prev;
      sel[r][c] = psel;
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> n >> m >> a;
  vector<vector<char>> g(n, vector<char>(m));
  P st = {-1, -1}, gl = {-1, -1};
  for(int i=0;i<(n);++i) {
    for(int j=0;j<(m);++j) {
      cin >> g[i][j];
      if(g[i][j] == 'S') {
        st = {i, j};
      }
      if(g[i][j] == 'G') {
        gl = {i, j};
      }
    }
  }
  dp.resize(n,
    vector<vector<vector<vector<bool>>>>(m,
      vector<vector<vector<bool>>>(a+1,
        vector<vector<bool>>(a+1,
          vector<bool>(4, false)))));
  vector<vector<bool>> sel(n, vector<bool>(m));
  dfs(st.first, st.second, 0, 0, 0, g, sel);
  int mi = INF;
  for(int i=0;i<(a+1);++i) {
    for(int j=0;j<(a+1);++j) {
      for(int k=0;k<(4);++k) {
        if(dp[gl.first][gl.second][i][j][k]) chmin(mi, i+j);
      }
    }
  }
  cout << (mi == INF ? -1 : mi) << endl;
}



Measured memory_bytes: 48564