#include<bits/stdc++.h>
using namespace std;

int main(){
  long long int N,M;
  cin >> N >> M;
  vector<pair<long long int,long long int>> vec(M);
  for(int i=0;i<M;i++){
    long long int X,Y;
    cin >> X >> Y;
    vec[i] = make_pair(X,Y);
  }
  sort(vec.begin(),vec.end());
  map<long long int,vector<int>> Map;
  for(int i=0;i<M;i++) Map[vec[i].first].push_back(vec[i].second);
  map<long long int,bool> P;
  P[N] = true;
  for(auto x:Map){
    vector<int> ope = x.second;
    map<long long int,int> judge;
    for(int i=0;i<ope.size();i++){
      long long int Y = ope[i];
      if(P[Y-1]) judge[Y] = 1;
      if(P[Y+1]) judge[Y] = 1;
      if(P[Y] && judge[Y] == 0) judge[Y] = 2;
    }
    for(auto y:judge){
      if(y.second == 1) P[y.first] = true;
      if(y.second == 2) P[y.first] = false;
    }
  }
  int ans = 0;
  for(auto x:P) if(x.second) ans++;
  cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    x--;
    y--;
    VS vs(h);
    REP(i, h) cin >> vs[i];

    int cnt = 1;
    FOR(i, x + 1, h - 1) {
        if (vs[i][y] == '#') break;
        cnt++;
    }
    FORR(i, x - 1, 0) {
        if (vs[i][y] == '#') break;
        cnt++;
    }
    FOR(i, y + 1, w - 1) {
        if (vs[x][i] == '#') break;
        cnt++;
    }
    FORR(i, y - 1, 0) {
        if (vs[x][i] == '#') break;
        cnt++;
    }

    cout << cnt << ln;
    return 0;
}
