#include<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
#include<cstdlib>
using namespace std;



int memo[102][102][4][11][11];
int field[102][102];
int A;

int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
struct aa {
	int y;
	int x;
	int way;
	int p;
	int q;
};
class Compare {
public:
	//keiroが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return 2*A-(l.p+l.q)> 2 * A - (r.p+r.q);
	}
};



int pc(const int way) {
	if (way == 0) {
		return 3;
	}
	else if (way == 1) {
		return 2;
	}
	else if (way == 2) {
		return 1;
	}
	else {
		return 0;
	}
}
int qc(const int way) {
	if (way == 0) {
		return 1;
	}
	else if (way == 1) {
		return 0;
	}
	else if (way == 2) {
		return 3;
	}
	else {
		return 2;
	}
}
int main() {
	memset(memo, -1, sizeof(memo));
	int N, M; cin >> N >> M >> A;
	for (int j = 0; j < M + 2; ++j) {
		field[0][j] = 0;
	}
	int sx, sy;
	int gx, gy;
	for (int i = 1; i <= N; ++i) {
		field[i][0] = 0;
		string st; cin >> st;
		for (int j = 0; j < M; ++j) {
			if (st[j] == 'S') {
				sx = j + 1;
				sy = i;
				field[i][j + 1] = 1;
			}
			else if (st[j] == 'G') {
				gx = j + 1;
				gy = i;
				field[i][j + 1] = 1;
			}
			else if (st[j] == '#') {
				field[i][j + 1] = 0;
			}
			else {
				field[i][j + 1] = 1;
			}
		}
		field[i][M+1] = 0;
	}
	for (int j = 0; j < M + 2; ++j) {
		field[N+1][j] = 0;
	}
	priority_queue<aa, vector<aa>, Compare>que;
	que.push(aa{ sy,sx,1,A,A });
	memo[sy][sx][1][A][A] = 1;
	
	int ans = -1;
	while (!que.empty()) {
		aa atop(que.top());
		que.pop();
		if (atop.x == gx&&atop.y == gy) {
			ans = A - atop.p + A - atop.q;
			break;
		}
		{
			const int nway = atop.way;
			if (field[atop.y + dy[nway]][atop.x + dx[nway]]) {
				if (memo[atop.y + dy[nway]][atop.x + dx[nway]][nway][atop.p][atop.q]<0) {
					memo[atop.y + dy[nway]][atop.x + dx[nway]][nway][atop.p][atop.q] = 1;
					bool ok = true;
					if (atop.y + dy[nway] == sy&&atop.x + dx[nway] == sx) {
						if (nway == 1 || nway == 3) {
							ok = false;
						}
					}
					if (ok) {
						que.push(aa{ atop.y + dy[nway], atop.x + dx[nway], nway, atop.p, atop.q });
					}
				}
			}
		}
		if (atop.x == sx&&atop.y == sy)continue;
		{
			if (atop.p) {
				const int nway = pc(atop.way);
				if (field[atop.y + dy[nway]][atop.x + dx[nway]]) {
					if (memo[atop.y + dy[nway]][atop.x + dx[nway]][nway][atop.p - 1][atop.q] < 0) {
						memo[atop.y + dy[nway]][atop.x + dx[nway]][nway][atop.p - 1][atop.q] = 1;
						bool ok = true;
						if (atop.y + dy[nway] == sy&&atop.x + dx[nway] == sx) {
							if (nway == 1 || nway == 3) {
								ok = false;
							}
						}
						if (ok) {
							que.push(aa{ atop.y + dy[nway], atop.x + dx[nway], nway, atop.p-1, atop.q });
						}
					}
				}
			}
		}
		{
			if (atop.q) {
				const int nway = qc(atop.way);
				if (field[atop.y + dy[nway]][atop.x + dx[nway]]) {
					if (memo[atop.y + dy[nway]][atop.x + dx[nway]][nway][atop.p][atop.q - 1] < 0) {
						memo[atop.y + dy[nway]][atop.x + dx[nway]][nway][atop.p][atop.q - 1] = 1;
						bool ok = true;
						if (atop.y + dy[nway] == sy&&atop.x + dx[nway] == sx) {
							if (nway == 1 || nway == 3) {
								ok = false;
							}
						}
						if (ok) {
							que.push(aa{ atop.y + dy[nway], atop.x + dx[nway], nway, atop.p, atop.q-1 });
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23016