#include <cstring>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

using namespace std;

char g[100][128];

int dp[11][100][100][4];

enum{
  LEFT = 0,
  DOWN = 1,
  RIGHT = 2,
  UP = 3
};

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

inline int encode(int a1, int a2, int x, int y, int dir){
  return dir | (y << 2) | (x << (2 + 8)) | (a2 << (2 + 8 + 8)) | (a1 << (2 + 8 + 8 + 4));
}

inline void decode(int val, int &a1, int &a2, int &x, int &y, int &dir){
  a1 = (val >> (2 + 8 + 8 + 4)) & ((1 << 4) - 1);
  a2 = (val >> (2 + 8 + 8)) & ((1 << 4) - 1);
  x = (val >> (2 + 8)) & ((1 << 8) - 1);
  y = (val >> (2)) & ((1 << 8) - 1);
  dir = val & ((1 << 2) - 1);
}

int main(){
  int h, w, a; scanf("%d%d%d", &h, &w, &a);
  REP(i,h) scanf("%s", g[i]);
  memset(dp, -1, sizeof(dp));

  priority_queue<int> pq;
  REP(i,h) REP(j,w) if(g[i][j] == 'S'){
    pq.push(encode(a, a, j, i, DOWN));
  }

  int ans = 100;
  while(pq.size()){
    int a1, a2, x, y, dir;
    int d = pq.top(); pq.pop();
    decode(d, a1, a2, x, y, dir);

    // printf("a1=%d a2=%d x=%d y=%d dir=%d\n", a1, a2, x, y, dir);
    if(g[y][x] == 'S' && dir == UP) continue;
    if(dp[a2][y][x][dir] != -1) continue;
    dp[a2][y][x][dir] = a1;

    if(g[y][x] == 'G'){
      ans = min(ans, (a - a1) + (a - a2));
    }

    REP(k,3){
      int dd = (dir + k + 3) % 4;
      int xx = x + dx[dd];
      int yy = y + dy[dd];
      if(g[y][x] == 'S' && k != 1) continue;
      if(ISIN(xx, yy, w, h) && (g[yy][xx] != '#' || g[yy][xx] == 'S')){
        int aa1 = a1;
        int aa2 = a2;
        if(k == 0){
          // turn right
          if(dir & 1) aa1--;
          else aa2--;
        }else if(k == 2){
          // turn left
          if(dir & 1) aa2--;
          else aa1--;
        }

        if(aa1 >= 0 && aa2 >= 0){
          if(dp[aa2][yy][xx][dd] == -1){
            pq.push(encode(aa1, aa2, xx, yy, dd));
          }
        }
      }
    }
  }

  if(ans == 100) puts("-1");
  else printf("%d\n", ans);

  return 0;
}