#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); (i)++)
#define all(x) (x).begin(), (x).end()
#define sqr(x) (x)*(x)
#define CEIL(a,b) ((a)+(b)-1) /(b)

typedef long long ll;
const int INF = 1001001001;

void sort_second(vector<pair<ll, ll>> &A, int N); //A:array of pair, N:size of array
ll a_n(ll a, ll n); // a^n

int main() {
    int n, k, m, sum = 0;
    cin >> n >> k >> m;
    rep(i, n-1) {
        int a;
        cin >> a;
        sum += a;
    }
    if(n*m - sum < 0) cout << 0 << endl;
    else if(n*m - sum <= k) cout << n*m -sum << endl;
    else cout << -1 << endl;

    return 0;
}

void sort_second(vector<pair<ll, ll>> &A, int N) {
    rep(i, N) swap(A.at(i).first, A.at(i).second);
    sort(all(A));
    rep(i, N) swap(A.at(i).first, A.at(i).second);
}
ll a_n(ll a, ll n) { 
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return ret * a_n(a, n-count) ;
}
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
//#include<bits/stdc++.h>
#define int long long
constexpr long long mod = 1000000007;
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << (x) << "\n"
using namespace std;
int input() {
	int r; cin >> r; //scanf("%lld", &r); 
	return r;
}
char map[2020][2020];
int px[2020][2020], h, w, gi, gj;
queue<pair<int, pair<int, int>>>q1;
vector<pair<int, int>>v[150]; bool b[150];
signed main() {
	cin >> h >> w;
	for0(i, h + 2)for0(j, w + 2) {
		if (i * j == 0)map[i][j] = '#';
		else if (i > h || j > w)map[i][j] = '#';
		else {
			cin >> map[i][j];
			px[i][j] = mod;
			if (map[i][j] == 'S') {
				q1.push(mp(0, mp(i, j)));
			}
			else if (map[i][j] == 'G') {
				gi = i; gj = j;
			}
			else if (map[i][j] != '.' && map[i][j] != '#')v[map[i][j]].push_back(mp(i, j));
		}
	}
	while (q1.size()) {
		int c = q1.front().first, i = q1.front().second.first, j = q1.front().second.second;
		q1.pop();
		if (px[i][j] < c)continue;
		px[i][j] = c;
		if (c > px[gi][gj] || (i == gi && j == gj)) {
			puts(px[gi][gj]); return 0;
		}
		if (map[i - 1][j] != '#' && px[i - 1][j] == mod) { px[i - 1][j] = c + 100; q1.push(mp(c + 1, mp(i - 1, j))); }
		if (map[i + 1][j] != '#' && px[i + 1][j] == mod) { px[i + 1][j] = c + 100; q1.push(mp(c + 1, mp(i + 1, j))); }
		if (map[i][j - 1] != '#' && px[i][j - 1] == mod) { px[i][j - 1] = c + 100; q1.push(mp(c + 1, mp(i, j - 1))); }
		if (map[i][j + 1] != '#' && px[i][j + 1] == mod) { px[i][j + 1] = c + 100; q1.push(mp(c + 1, mp(i, j + 1))); }
		if ('a' <= map[i][j] && map[i][j] <= 'z' && !b[map[i][j]]) {
			b[map[i][j]] = 1;
			for (pair<int, int>p1 : v[map[i][j]]) 
				if (px[p1.first][p1.second] == mod) { px[p1.first][p1.second] = c + 100; q1.push(mp(c + 1, mp(p1.first, p1.second))); }
		}
	}
	puts(-1); return 0;
}