#include <iostream>
#include <queue>
#include <cassert>
using namespace std;

int H,W,A;
char F[110][110];
int vis[110][110][11][11][4] = {};
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

struct state{
    int x,y,p,q,d;
    bool in(){
        return 1<=x && x<=H && 1<=y && y<=W;
    }
};

int main(){
    cin >> H >> W >> A;
    int sx,sy,gx,gy;
    for(int i=0;i<=H+1;i++) for(int j=0;j<=W+1;j++) F[i][j] = '#';
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){
        cin >> F[i][j];
        if(F[i][j]=='S'){
            sx = i; sy = j;
        }
        if(F[i][j]=='G'){
            gx = i; gy = j;
        }
    }
    queue<state> Q;
    vis[sx][sy][A][A][0] = 1;
    Q.push({sx,sy,A,A,0});
    while(!Q.empty()){
        state now = Q.front(); Q.pop();
        //cerr << now.x << " " << now.y << " " << now.d << endl;
        assert(F[now.x][now.y]!='#');
        if(now.d==0){
            for(int j=0;j<=1;j++){
                if(now.x==sx && now.y==sy && j==0) continue;
                if(j==1 && F[now.x+1][now.y]=='#') continue;
                for(int i=-1;i<=1;i++){
                    state ne = now;
                    ne.x += j; ne.y += i;
                    if(!ne.in() || F[ne.x][ne.y]=='#') continue;
                    if(i==-1){ne.q--; ne.d = 3;}
                    if(i==1){ne.p--; ne.d = 1;}
                    if(ne.q>=0 && ne.p>=0 && !vis[ne.x][ne.y][ne.p][ne.q][ne.d]){
                        vis[ne.x][ne.y][ne.p][ne.q][ne.d] = 1;
                        Q.push(ne);
                    }
                }
            }
        }else if(now.d==1){
            for(int j=0;j<=1;j++){
                if(j==1 && F[now.x][now.y+1]=='#') continue;
                for(int i=-1;i<=1;i++){
                    if(now.x==sx && now.y==sy && i!=0) continue;
                    state ne = now;
                    ne.x += i; ne.y += j;
                    if(!ne.in() || F[ne.x][ne.y]=='#') continue;
                    if(i==-1){ne.q--; ne.d = 2;}
                    if(i==1){ne.p--; ne.d = 0;}
                    if(ne.q>=0 && ne.p>=0 && !vis[ne.x][ne.y][ne.p][ne.q][ne.d]){
                        vis[ne.x][ne.y][ne.p][ne.q][ne.d] = 1;
                        Q.push(ne);
                    }
                }
            }
        }else if(now.d==2){
            if(now.x==sx && now.y==sy) continue;
            for(int j=-1;j<=0;j++){
                if(j==-1 && F[now.x-1][now.y]=='#') continue;
                for(int i=-1;i<=1;i++){
                    state ne = now;
                    ne.x += j; ne.y += i;
                    if(!ne.in() || F[ne.x][ne.y]=='#') continue;
                    if(i==-1){ne.p--; ne.d = 3;}
                    if(i==1){ne.q--; ne.d = 1;}
                    if(ne.q>=0 && ne.p>=0 && !vis[ne.x][ne.y][ne.p][ne.q][ne.d]){
                        vis[ne.x][ne.y][ne.p][ne.q][ne.d] = 1;
                        Q.push(ne);
                    }
                }
            }
        }else{
            for(int j=-1;j<=0;j++){
                for(int i=-1;i<=1;i++){
                    if(now.x==sx && now.y==sy && i!=0) continue;
                    if(j==-1 && F[now.x][now.y-1]=='#') continue;
                    state ne = now;
                    ne.x += i; ne.y += j;
                    if(!ne.in() || F[ne.x][ne.y]=='#') continue;
                    if(i==-1){ne.p--; ne.d = 2;}
                    if(i==1){ne.q--; ne.d = 0;}
                    if(ne.q>=0 && ne.p>=0 && !vis[ne.x][ne.y][ne.p][ne.q][ne.d]){
                        vis[ne.x][ne.y][ne.p][ne.q][ne.d] = 1;
                        Q.push(ne);
                    }
                }
            }
        }
    }
    int inf = 1e9,ans = inf;
    for(int i=0;i<=A;i++) for(int j=0;j<=A;j++) for(int k=0;k<4;k++){
        if(vis[gx][gy][i][j][k]) ans = min(ans,2*A-i-j);
    }
    cout << (ans!=inf? ans:-1) << endl;
}


Measured memory_bytes: 16140