#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=105,INF=1<<30;
int H,W,K,sh,sw,gh,gw;
char S[MAX][MAX];
short can[MAX][MAX][MAX][11][4];

vector<int> dh={0,1,0,-1},dw={1,0,-1,0};

struct dat{
    int h;
    int w;
    int x;
    int b;
    int dir;
};

void BFS(){
    deque<dat> deq;
    can[sh][sw][H+1][0][1]=0;
    deq.push_front({sh,sw,H+1,0,1});
    
    while(!deq.empty()){
        auto u=deq.front();deq.pop_front();
        int h=u.h,w=u.w,x=u.x,b=u.b,dir=u.dir;
        if(h<0||h>=H||w<0||w>=W) continue;
        short a=can[h][w][x][b][dir];
        if(a>K||b>K) continue;
        if(S[h][w]=='#') continue;
        if((a||b)&&x==H+1) continue;
        if(w==sw&&x!=H+1&&sh<=h&&h<=x&&dir==3) continue;
        
        if(h+dh[dir]>=0&&w+dw[dir]>=0&&chmin(can[h+dh[dir]][w+dw[dir]][x][b][dir],a)) deq.push_front({h+dh[dir],w+dw[dir],x,b,dir});
        
        if(h==sh&&w==sw) continue;
        if(h==gh&&w==gw) continue;
        
        for(int k=0;k<4;k++){
            if((k&1)==(dir&1)) continue;
            
            if(dir/2==k/2){
                if(x==H+1&&w==sw){
                    if(chmin(can[h][w][h][b][k],short(a+1))){
                        deq.push_back({h,w,h,b,k});
                    }
                }else{
                    if(chmin(can[h][w][x][b][k],short(a+1))){
                        deq.push_back({h,w,x,b,k});
                    }
                }
            }
            else{
                if(x==H+1&&w==sw){
                    if(chmin(can[h][w][h][b+1][k],short(a))){
                        deq.push_front({h,w,h,b+1,k});
                    }
                }else{
                    if(chmin(can[h][w][x][b+1][k],short(a))){
                        deq.push_front({h,w,x,b+1,k});
                    }
                }
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>H>>W>>K;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>S[i][j];
            if(S[i][j]=='S'){
                sh=i;
                sw=j;
            }
            if(S[i][j]=='G'){
                gh=i;
                gw=j;
            }
        }
    }
    
    for(int i=0;i<=H;i++){
        for(int j=0;j<=W;j++){
            for(int k=0;k<=H+1;k++){
                for(int b=0;b<11;b++){
                    for(int l=0;l<4;l++){
                        can[i][j][k][b][l]=100;
                    }
                }
            }
        }
    }
    
    BFS();
    
    int ans=INF;
    
    for(int k=0;k<=H+1;k++){
        for(int b=0;b<=K;b++){
            for(int l=0;l<4;l++){
                if(can[gh][gw][k][b][l]<=K){
                    chmin(ans,b+can[gh][gw][k][b][l]);
                }
            }
        }
    }
    
    if(ans>2*K) ans=-1;
    
    cout<<ans<<endl;
}



Measured memory_bytes: 78216