#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    int h,w,x,y;
    cin >> h >> w >> x >> y;
    vector<string> s(h);
    for(int i = 0;i < h;i++){
        cin >> s[i];
    }
    x--;
    y--;
    int ans = 1;
    for(int i =y+1;i < w;i++){
        if(s[x][i] == '.'){
            ans ++;
        }else{
            break;
        }
    }
    for(int i = y-1;0 <= i;i--){
        if(s[x][i] == '.'){
            ans ++;
        }else{
            break;
        }
    }
    for(int i = x+1;i < h;i++){
        if(s[i][y] == '.'){
            ans ++;
        }else{
            break;
        }
    }
    for(int i = x-1;0 <= i;i--){
        if(s[i][y] == '.'){
            ans ++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


// edit

template<typename T>
class graph {
    struct edge {
        int src, to;
        T cost;
    };

public:
    int n;
    vector<vector<edge>> edges;

    graph(int n_) : n(n_), edges(n_) {
    }

    void add_edge(int src, int to, T cost) {
        edges[src].push_back({src, to, cost});
    }
};

template<typename T>
pair<vector<T>, vector<int>> dijkstra(const graph<T> &g, int s, T inf) {
    vector<T> d(g.edges.size(), inf);
    vector<int> p(g.edges.size());

    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;

    que.emplace(0, s);
    d[s] = 0;
    p[s] = -1;

    while (!que.empty()) {
        T cost;
        int v;
        tie(cost, v) = que.top();
        que.pop();

        if (d[v] < cost) continue;
        for (const auto &e : g.edges[v]) {
            T ncost = cost + e.cost;
            int nv = e.to;
            if (ncost < d[nv]) {
                d[nv] = ncost;
                p[nv] = v;
                que.emplace(ncost, nv);
            }
        }
    }

    return make_pair(d, p);
}

void solve() {
    int N, M;
    cin >> N >> M;
    graph<int> G(N + 1);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        G.add_edge(a, b, 0);
    }

    int ans = 0;
    for (int s = 1; s <= N; ++s) {
        auto tapu = dijkstra(G, s, INF).first;
        int cnt = 0;
        for (int i = 1; i <= N; ++i) {
            if (tapu[i] == 0) {
                cnt++;
            }
        }
        ans += cnt;
    }
    cout << ans << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}
