#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int d=2,h,w,n,sx,sy,gx,gy,ans=-1;
bool dp[111][111][4][11][11];
string s[111];
struct T{
    int y,x,d,l,r,cost;
    T(int a,int b,int c,int f,int e,int w){y=a,x=b,d=c,l=f,r=e,cost=w;}
};
signed main(){
    cin>>h>>w>>n;
    r(i,h)cin>>s[i];
    r(i,h)r(j,w){
        if(s[i][j]=='S')sy=i,sx=j;
        if(s[i][j]=='G')gy=i,gx=j;
    }
    deque<T>q;
    q.push_back(T(sy,sx,2,0,0,0));
    dp[sy][sx][2][0][0]=1;
    while(!q.empty()){
        T a=q.front();q.pop_front();
        d=a.d;
        if(s[a.y][a.x]=='G'){ans=a.cost;break;}
        if(d==0&&s[a.y][a.x]=='S')continue;
        int y=a.y+dy[d];
        int x=a.x+dx[d];
        if(y<0||x<0||y>=h||x>=w)continue;
        if(s[y][x]=='#')continue;
        if(1){
            T t=T(y,x,d,a.l,a.r,a.cost);
            if(dp[y][x][d][a.l][a.r+1])continue;
            dp[y][x][d][a.l][a.r+1]=1;
            q.push_front(t);
        }
        if(a.l<n){
            T t=T(y,x,3-d,a.l+1,a.r,a.cost+1);
            if(dp[y][x][3-d][a.l+1][a.r])continue;
            dp[y][x][3-d][a.l+1][a.r]=1;
            q.push_back(t);
        }
        if(a.r<n){
            T t=T(y,x,d^1,a.l,a.r+1,a.cost+1);
            if(dp[y][x][d^1][a.l][a.r+1])continue;
            dp[y][x][d^1][a.l][a.r+1]=1;
            q.push_back(t);
        }
    }
    cout<<ans<<endl;
}
