#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;


int main(){
    int x,y;
    cin>>x>>y;

    int r=min(x,y);
    int m=max(x,y);

    if(r+3>m)cout<<"Yes";
    else{
        cout<<"No";
    }
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0};
V<int> dy = { 0, 0, -1, 1};

int main () {
    int h, w; cin >> h >> w;
    V<string> a(h); rep(i, h) cin >> a[i];
    V<V<int>> d(h, V<int> (w, -1));
    int sx, sy, gx, gy;
    V<set<P>> st(26);
    rep(i, h) rep(j, w) {
        if (a[i][j] == 'S') {
            sx = i, sy = j;
        }
        if (a[i][j] == 'G') {
            gx = i, gy = j;
        }
        if ('a' <= a[i][j] && a[i][j] <= 'z') {
            st[a[i][j] - 'a'].insert({i, j});
        }
    }
    d[sx][sy] = 0;
    queue<P> que;
    que.push({sx, sy});
    V<bool> checked(26, false);
    while (!que.empty()) {
        auto v = que.front(); que.pop();
        int x = v.first, y = v.second;
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (a[nx][ny] == '#') continue;
            if (d[nx][ny] != -1) continue;
            d[nx][ny] = d[x][y] + 1;
            que.push({nx, ny});
        }
        if ('a' <= a[x][y] && a[x][y] <= 'z') {
            int m = a[x][y] - 'a';
            if (checked[m]) continue;
            for (auto p : st[m]) {
                int nx = p.first, ny = p.second;
                if (d[nx][ny] != -1) continue;
                d[nx][ny] = d[x][y] + 1;
                que.push({nx, ny});
            }
            //checked[m] = true;
            st[m] = set<P> ();
        }
    }
    cout << d[gx][gy] << endl;
    return 0;
}