#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int h, w, n, m;
  cin >> h >> w >> n >> m;
  vector<vector<int>> field(h, vector<int>(w, 0));
  rep(i,0,n) {
    int a, b;
    cin >> a >> b;
    field[a-1][b-1] = 1;
  }
  rep(i,0,m) {
    int c, d;
    cin >> c >> d;
    field[c-1][d-1] = 2;
  }
  rep(i,0,h) {
    bool ok = false;
    rep(j,0,w) {
      if (field[i][j] == 1) {
        ok = true;
      } else if (field[i][j] == 2) {
        ok = false;
      } else {
        if (ok) field[i][j] = 3;
      }
    }
    ok = false;
    rrep(j,w,0) {
      if (field[i][j] == 1) {
        ok = true;
      } else if (field[i][j] == 2) {
        ok = false;
      } else {
        if (ok) field[i][j] = 3;
      }
    }
  }
  rep(j,0,w) {
    bool ok = false;
    rep(i,0,h) {
      if (field[i][j] == 1) {
        ok = true;
      } else if (field[i][j] == 2) {
        ok = false;
      } else {
        if (ok) field[i][j] = 3;
      }
    }
    ok = false;
    rrep(i,h,0) {
      if (field[i][j] == 1) {
        ok = true;
      } else if (field[i][j] == 2) {
        ok = false;
      } else {
        if (ok) field[i][j] = 3;
      }
    }
  }
  int ans = 0;
  rep(i,0,h) rep(j,0,w) {
    if (field[i][j] == 1 || field[i][j] == 3) ans++;
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define DAU  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
const int dx[] {1, -1, 0, 0};
const int dy[] {0, 0, 1, -1};
char mat[2002][2002];
int dp[2002][2002], n, m, x, y, xv, yv;
pair<int, int> stop, curr;
vector<pair<int, int>> telep[30];
queue<pair<int, int>> q;
inline bool Inside(int a, int b) {
    return (1 <= a && a <= n && 1 <= b && b <= m);
}
int32_t main() {
    DAU
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> (mat[i] + 1);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j) {
            dp[i][j] = 1e9;
            if (mat[i][j] == 'S') {
                q.emplace(i, j);
                dp[i][j] = 0;
            }
            else if (mat[i][j] == 'G')
                stop = {i, j};
            else if ('a' <= mat[i][j] && mat[i][j] <= 'z')
                telep[mat[i][j] - 'a'].emplace_back(i, j);
        }
    while (!q.empty()) {
        tie(x, y) = q.front();
        q.pop();
        for (int dir = 0; dir < 4; ++dir) {
            xv = x + dx[dir];
            yv = y + dy[dir];
            if (Inside(xv, yv) && mat[xv][yv] != '#' && dp[xv][yv] > dp[x][y] + 1) {
                dp[xv][yv] = dp[x][y] + 1;
                q.emplace(xv, yv);
            }
        }
        if(mat[x][y] >= 'a' && mat[x][y] <= 'z') {
            int val = mat[x][y] - 'a';
            while (!telep[val].empty()) {
                int xv = telep[val].back().first,
                    yv = telep[val].back().second;
                telep[val].pop_back();
                if(dp[xv][yv] > dp[x][y] + 1) {
                    dp[xv][yv] = dp[x][y] + 1;
                    q.emplace(xv, yv);
                }
            }
        }
    }
    tie(x, y) = stop;
    if (dp[x][y] == 1e9)
        dp[x][y] = -1;
    cout << dp[x][y];
    PLEC
}
