#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define forn(i,x,n) for(int i = x; i < n; ++i)

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	int n,m,s,g;
	
	cin>>n>>m;
	vector<int> dist(n*m);
	vector<bool> done(n*m,false);
	vector<vector<int>> adj(n*m);
	unordered_map<char,vector<int>> teleport;
	vector<string> a(n);
	forn(i,0,n)
		cin>>a[i];
	forn(i,0,n)
		forn(j,0,m){
			dist[i*m+j]=INT_MAX;
			if(a[i][j]!='#' && a[i][j]!='.')
				teleport[a[i][j]].push_back(i*m+j);
			if(a[i][j]=='S')
				s=i*m+j;
			if(a[i][j]=='G')
				g=i*m+j;
			if(i && a[i-1][j]!='#')
				adj[i*m+j].push_back((i-1)*m+j);
			if(j && a[i][j-1]!='#')
				adj[i*m+j].push_back(i*m+j-1);
			if(i<n-1 && a[i+1][j]!='#')
				adj[i*m+j].push_back((i+1)*m+j);
			if(j<m-1 && a[i][j+1]!='#')
				adj[i*m+j].push_back(i*m+j+1);
		}

	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    dist[s]=0;
    q.push({dist[s],s});

    while(q.size()){
        int f = q.top().second;
        q.pop();
        if(done[f])
        	continue;
        done[f]=true;
        for(auto v: adj[f])
            if(dist[v]>dist[f]+1)
                dist[v]=dist[f]+1, q.push({dist[v],v});
        if(teleport.find(a[f/m][f%m])!=teleport.end()){
        	for(auto v:teleport[a[f/m][f%m]])
	        	if(dist[v]>dist[f]+1)
	                dist[v]=dist[f]+1, q.push({dist[v],v});
        	teleport.erase(a[f/m][f%m]);
        }
    }
	cout<<(dist[g]==INT_MAX?-1:dist[g]);
}
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 

const int N = 1e5 + 2;

void Solve() {
    long long t, n;
    cin>>t>>n;
    long long ans = ceil((100.0*n)/t);
    cout<<ans+n-1<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    // #endif
    
    // int T;cin>>T;while(T--) 
    {
        Solve();
    }
    return 0;
}