//22
#include<iostream>
#include<deque>

using namespace std;

struct S{
  int y,x,d,p,q;
};

int main(){
  int N,M,A;
  cin>>N>>M>>A;
  char g[100][100];
  S is={0,0,2,0,0};
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>g[i][j];
      if(g[i][j]=='S'){
	is.y=i;
	is.x=j;
      }
    }
  }
  static bool p[100][100][4][11][11];
  deque<S> deq(1,is);
  while(!deq.empty()){
    S c=deq.front();
    if(g[c.y][c.x]=='G')break;
    deq.pop_front();
    if(p[c.y][c.x][c.d][c.p][c.q]++)continue;
    for(int i=0;i<((g[c.y][c.x]=='S')?1:3);i++){
      static int dy[]={-1,0,1,0};
      static int dx[]={0,1,0,-1};
      S n=c;
      if(i==1){
	n.d^=1;
	n.p++;
      }else if(i==2){
	n.d=3-n.d;
	n.q++;
      }
      n.y+=dy[n.d];
      n.x+=dx[n.d];
      if(0<=n.y&&n.y<N&&0<=n.x&&n.x<M&&n.p<=A&&n.q<=A&&g[c.y][c.x]!='#'&&!(g[c.y][c.x]=='S'&&n.d==0)){
	if(i==0){
	  deq.push_front(n);
	}else{
	  deq.push_back(n);
	}
      }
    }
  }
  cout<<(deq.empty()?-1:deq.front().p+deq.front().q)<<endl;
  return 0;
}