#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define rep(i,n) for (ll i = 0;i<(n);++i)
#define all(v) v.begin(),v.end()

template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}

int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}

const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=2*1e9;



void Main();
int main(){cout<<fixed<<setprecision(15);Main();}

void Main(){

int H,W,X,Y;
cin>>H>>W>>X>>Y;
X--;Y--;
vector<string> S(H);
rep(i,H)cin>>S[i];
int cnt=-3;
for(int i=X;i>=0;--i){
    if(S[i][Y]=='#')break;
    ++cnt;
}
for(int i=X;i<H;++i){
    if(S[i][Y]=='#')break;
    ++cnt;
}
for(int j=Y;j>=0;--j){
    if(S[X][j]=='#')break;
    ++cnt;
}
for(int j=Y;j<W;++j){
    if(S[X][j]=='#')break;
    ++cnt;
}
cout<<cnt<<endl;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (200006)
int h, w;
string A[1002], B[1002];
int p[1002], sz[1002];
void init() {
	FOR(i,0,1001) p[i]=i, sz[i]=1;
}
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void merge(int a,int b) {
	a = find(a), b = find(b);
	if(a==b) return;
	if(sz[a]>sz[b]) swap(a, b);
	sz[b]+=sz[a], p[a]=b;
}
ll solve() {
	init();
	int ans = 0;
	A[0][0] = A[0].back() = A[h-1][0] = A[h-1].back() = '#';
	FOR(j,0,w-1) {
		ll pre = -1;
		FOR(i,0,h-1) {
			if(A[i][j] != '#') continue;
			if(~pre) merge(pre, i);
			pre = i;
		}
	}
	FOR(i,0,h-1) if(find(i) == i) ++ ans;
	-- ans;
	return ans;
}
void copy() {
	FOR(i,0,h-1) A[i]=B[i];
}
int main() {
	FAST
	cin>>h>>w;
	FOR(i,0,h-1) cin>>B[i];
	copy();
	ll ans = solve();
	// invert
	for(auto&i:A) i.clear();
	FOR(i,0,w-1) A[i].resize(h);
	FOR(i,0,h-1) FOR(j,0,w-1) A[j][i]=B[i][j];
	swap(h, w);
	ans = min(ans, solve());
	cout<<ans<<'\n';
}
