#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n, m, x, y;
    cin >> n >> m >> x >> y;
    x--, y--;
    vector<string> g(n);
    for (int i = 0; i < n; i++) cin >> g[i];

    int ans = 0;
    for (int i = x; i < n && g[i][y] != '#'; i++) ans++;
    for (int j = y; j < m && g[x][j] != '#'; j++) ans++;
    for (int i = x; i >= 0 && g[i][y] != '#'; i--) ans++;
    for (int j = y; j >= 0 && g[x][j] != '#'; j--) ans++;

    cout << ans - 3 << '\n';

    return 0;
}
#include<bits/stdc++.h>
#define ll long long
#define pb emplace_back
#define INF 0x3f3f3f3f
#define f first
#define s second
#define FOR(i, n) for(int i = 1; i <= n; i ++)
#define FFOR(i, a, b) for(int i = a; i <= b; i ++)
#define pii pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mem(x, a) memset(x, a, sizeof(x))
#define loli ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int maxn = 1e6 + 50;

bitset<maxn> vis;
int n, m, a[20], to[20][maxn], b[maxn], dp[1 << 18][20];
vector<int> vc[maxn];

signed main(){
	loli;
	cin >> n >> m;
	FOR(i, m) {
		int a, b;
		cin >> a >> b;
		vc[a].pb(b);
		vc[b].pb(a);
	}
	int k;
	cin >> k;
	mem(to, INF);
	FOR(i, k) cin >> a[i], b[a[i]] = i;
	FOR(i, k) {
		queue<int> q;
		q.push(a[i]);
		to[i][a[i]] = 0;
		vis = 0;
		vis[a[i]] = 1;
		while(!q.empty()) {
			int a = q.front(); q.pop();
			for(int t : vc[a]) {
				if(vis[t]) continue;
				to[i][t] = to[i][a] + 1;
				vis[t] = 1;
				q.push(t);
			}
		}
	}
	vis = 0;
	int ans = INF;
	/*
	cout << ans << endl;
	FOR(i, k) {
		FOR(j, k) cout << to[i][a[j]] << " ";
		cout << "\n";
	}
	*/
	mem(dp, INF);
	for(int i = 0; i < k; i ++) dp[(1 << i)][i] = 0;
	for(int i = 1; i < (1 << k); i ++) {
		for(int j = 0; j < k; j ++) {
			if((i >> j) & 1) {
				for(int u = 0; u < k; u ++) {
					if(j != u and ((i >> u) & 1)) {
						dp[i][u] = min(dp[i][u], dp[i ^ (1 << u)][j] + to[j + 1][a[u + 1]]);
					}
				}
			}
		}
	}
	int t = *min_element(dp[(1 << k) - 1], dp[(1 << k) - 1] + k);
	cout << (t == INF? -1 : t + 1) << "\n";
}

