#include <bits/stdc++.h>
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int h = ri();
	int w = ri();
	int x = ri() - 1;
	int y = ri() - 1;
	std::string s[h];
	for (auto &i : s) std::cin >> i;
	
	int cnt = -3;
	for (int i = x; i < h && s[i][y] != '#'; i++) cnt++;
	for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++;
	for (int j = y; j < w && s[x][j] != '#'; j++) cnt++;
	for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++;
	printf("%d\n", cnt);
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int cnt;
int vis[2005];
vector<int>adj[20005];
void dfs(int v)
{
    vis[v] =1;
    cnt++;

    for(auto u: adj[v]){
        if(vis[u]==0)
            dfs(u);
    }
}
int main()
{
    int n, m;
    cin >> n >>m ;
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    int ans=0;
    for(int i=1;i<=n;i++){
        memset(vis, 0 , sizeof vis);
        cnt=0;
        dfs(i);
        ans+=cnt;
    }

    cout << ans << endl;
}
