#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int, int> P;

const int MAX_N = 2010;
int n, m;
vector<int> g[MAX_N];
bool check[MAX_N];
int ans = 0;

void dfs(int s){
    ans++;
    check[s] = true;
    for(auto next : g[s]){
        if(!check[next]){
            dfs(next);
        }
    }
}

void solve(){
    //dfsでいけるところまでいく
    rep(i, n){
        rep(j, n) check[j] = false;
        dfs(i);
    }
    cout << ans << endl;
}

int main(void){
    cin >> n >> m;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
    }
    solve();
    return 0;
}

#include <bits/stdc++.h>
/*
 * autor:NEU-Yuan
 * Email:yuanyanghao2022@163.com
 * Time: 2021/04/12 10:53:09
 */
#define pcc pair<char, char>
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for (int i = x; i < y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define rep0(i, n) for (int i = 0; i < (n); i++)
#define per0(i, n) for (int i = (n)-1; i >= 0; i--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
using namespace std;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}

const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 6e6 + 10;
const int MAX = 1e5;
const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f;
ll qpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res % mod;
}
/***************main****************/
ll T = 1;
ll m, n;
int main() {
  int h, w, x, y, cnt = 0;
  cin >> h >> w >> x >> y;
  string s[105];
  for (int i = 1; i <= h; i++) {
    cin >> s[i];
    s[i] = "#" + s[i];
  }
  for (int i = y - 1; i >= 1; i--)
    if (s[x][i] == '#')
      break;
    else
      cnt++;
  for (int i = y; i <= w; i++)
    if (s[x][i] == '#')
      break;
    else
      cnt++;
  for (int i = x + 1; i <= h; i++)
    if (s[i][y] == '#')
      break;
    else
      cnt++;
  for (int i = x - 1; i >= 1; i--)
    if (s[i][y] == '#')
      break;
    else
      cnt++;
  cout << cnt << endl;
  return 0;
}
