#include<bits/stdc++.h>

using namespace std;

const int INF = 1 << 30;

typedef tuple< int, int, int, int, int, int > Pi;
const int vy[] = {1, 0, -1, 0}, vx[] = {0, -1, 0, 1};

int v[100][100][11][11][4];

int main()
{
  int N, M, A;
  string S[100];

  cin >> N >> M >> A;
  for(int i = 0; i < N; i++) cin >> S[i];


  int sy, sx;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < M; j++) {
      if(S[i][j] == 'S') sy = i, sx = j;
    }
  }

  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.emplace(0, sy, sx, A, A, 0);
  fill_n(****v, 100 * 100 * 11 * 11 * 4, INF);
  v[sy][sx][A][A][0] = 0;

  auto isover = [&](int y, int x) -> bool
  {
    return (y < 0 || y >= N || x < 0 || x >= M || S[y][x] == '#');
  };

  while(!que.empty()) {
    int y, x, latte, malta, dir, cost;
    tie(cost, y, x, latte, malta, dir) = que.top();
    que.pop();
    if(S[y][x] == 'G') {
      cout << cost << endl;
      return (0);
    }
    if(v[y][x][latte][malta][dir] > cost) continue;
    for(int i = -1; i <= 1; i++) {
      int beet = (dir + i + 4) % 4;
      int ll = latte, rr = malta;
      int ny = y + vy[beet], nx = x + vx[beet];
      if(isover(ny, nx)) continue;
      if(S[y][x] == 'S' && i != 0) continue;
      if(S[ny][nx] == 'S' && beet == 2) continue;
      if(i != 0) {
        if((beet + (i == 1)) % 2 == 1) --ll;
        else --rr;
      }
      if(ll >= 0 && rr >= 0 && cost + (i != 0) < v[ny][nx][ll][rr][beet]) {
        v[ny][nx][ll][rr][beet] = cost + (i != 0);
        que.emplace(cost + (i != 0), ny, nx, ll, rr, beet);
      }
    }
  }
  cout << -1 << endl;
}