#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct State {
  // d:??\??£???????????????
  int y, x, d, p, q, cost;
  State(){}
  State(int y, int x, int d, int p, int q, int cost):
    y(y), x(x), d(d), p(p), q(q), cost(cost){}
  bool operator < (const State &s) const {
    return cost > s.cost;
  }
};

int N, M, A;
char mas[101][101];
int sy, sx, gy, gx;
int mincost[4][11][11][101][101];

int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};

bool in(int y, int x) {
  return 0<=y&&y<N&&0<=x&&x<M;
}

int dijkstra() {
  rep(i, 4) rep(j, 11) rep(k, 11) {
    rep(y, 101) rep(x, 101) mincost[i][j][k][y][x] = inf;
  }
  priority_queue<State> que;
  que.push(State(sy, sx, 0, A, A, 0));
  mincost[0][A][A][sy][sx] = 0;
  while(!que.empty()) {
    State s = que.top(); que.pop();
    //cout<<s.y<<" "<<s.x<<" "<<s.d<<" "<<s.cost<<endl;
    if(s.y == gy && s.x == gx) return s.cost;
    if(mincost[s.d][s.p][s.q][s.y][s.x] < s.cost) continue;
    if(s.y == sy && s.x == sx) {
      if(s.cost > 0 && (s.d == 0 || s.d == 2)) continue;
      int ny = s.y+dy[(s.d+2)%4], nx = s.x+dx[(s.d+2)%4];
      if(in(ny, nx) && mas[ny][nx] != '#') {
	if(s.cost < mincost[s.d][s.p][s.q][ny][nx]) {
	  que.push(State(ny, nx, s.d, s.p, s.q, s.cost));
	  mincost[s.d][s.p][s.q][ny][nx] = s.cost;
	}
      }
      continue;
    }
    rep(i, 4) {
      if(s.d == i) continue;
      int np = s.p, nq = s.q, ncost = s.cost;
      if(s.d == 0) {
	if(i == 1) nq--, ncost++;
	else if(i == 3) np--, ncost++;
      } else if(s.d == 1) {
	if(i == 0) nq--, ncost++;
	else if(i == 2) np--, ncost++;
      } else if(s.d == 2) {
	if(i == 1) np--, ncost++;
	else if(i == 3) nq--, ncost++;
      } else if(s.d == 3) {
	if(i == 0) np--, ncost++;
	else if(i == 2) nq--, ncost++;
      }
      if(np < 0 || nq < 0) continue;
      int ny = s.y+dy[i], nx = s.x+dx[i];
      if(!in(ny, nx) || mas[ny][nx] == '#') continue;
      if(ncost < mincost[(i+2)%4][np][nq][ny][nx]) {
	//cout<<s.y<<" "<<s.x<<" "<<s.d<<" "<<ny<<" "<<nx<<" "<<(i+2)%4<<" "<<ncost<<endl;
	que.push(State(ny, nx, (i+2)%4, np, nq, ncost));
	mincost[(i+2)%4][np][nq][ny][nx] = ncost;
      }
    }
  }
  return -1;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M >> A;
  rep(i, N) rep(j, M) {
    cin >> mas[i][j];
    if(mas[i][j] == 'S') sy = i, sx = j;
    else if(mas[i][j] == 'G') gy = i, gx = j;
  }
  cout << dijkstra() << endl;

  return 0;
}