#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
//vector<vector<bool>> seat;

int main(){
    ll h,w,x,y;
    cin>>h>>w>>x>>y;
    vector<vector<char> > s(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin>>s[i][j];
        }
    }
    x--;y--;
    ll ans=0;
    for(ll i=x;i<h;i++){
        if(s[i][y]=='.'){
           // cout<<i<<" "<<y<<endl;
            ans++;
        }else{
            break;
        }
    }
    for(ll i=x-1;i>=0;i--){
        if(s[i][y]=='.'){
            ans++;
        }else{
            break;
        }
    }
    for(ll i=y+1;i<w;i++){
        //cout<<s[x][i]<<endl;
        if(s[x][i]=='.'){
           //cout<<x<<" "<<i<<endl;
            ans++;
        }else{
            break;
        }
    }
    for(ll i=y-1;i>=0;i--){
        if(s[x][i]=='.'){
            //cout<<x<<" "<<i<<endl;
            ans++;
        }else{
            break;
        }
    }
    cout<<ans<<endl;
    
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plp;
typedef pair<pll,ll> ppl;
typedef pair<pll,pll> ppp;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pll> vpll;
typedef vector<plp> vplp;
typedef vector<ppl> vppl;
typedef vector<ppp> vppp;
typedef vector<vpll> vvpll;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<double> vd;
typedef priority_queue<pll,vpll,greater<pll> > pqpll;
typedef priority_queue<pll,vpll> pqrpll;
typedef priority_queue<ll, vll, greater<ll> > pqll;
typedef priority_queue<ll, vll> pqrll;

struct edge{ ll to,cost; edge(ll to,ll cost): to(to), cost(cost){} };
typedef vector<vector<edge>> Graph;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF 1000000000000000000
#define INF 1000000000
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) a.begin(), a.end()

template<typename T> ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 

void chmin(ll &a, ll &b) { if(a > b) a = b; }
void chmax(ll &a, ll &b) { if(a < b) a = b; }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1};
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }
vbool is_visited(200000,false);

void dfs(ll k, vll &a, vll &minnum, vvll &G){
    rep(i,0,sz(G[k])){
        if(!is_visited[G[k][i]]){
            is_visited[G[k][i]] = true;
            dfs(G[k][i], a, minnum, G);
        }
        minnum[k] = min(minnum[k],min(minnum[G[k][i]],a[G[k][i]]));
    }
}

int main(){
    ll n,m;
    cin >> n >> m;
    vll a(n);
    rep(i,0,n) cin >> a[i];
    vvll G(n);

    rep(i,0,m){
        ll x,y;
        cin >> x >> y;
        x--; y--;
        G[y].push_back(x);
    }

    vll minnum(n,LINF);
    rep(i,0,n){
        if(!is_visited[i]){
            is_visited[i] = true;
            dfs(i,a,minnum,G);
        }
    }

    ll ans = -LINF;
    rep(i,0,n){
        ans = max(ans,a[i]-minnum[i]);
    }
    assert(ans != -LINF);
    cout << ans << endl;

    return 0;
}