#include<cstdio>
#include<iostream>
#define M 16
using namespace std;
char map[M][M];
int vis[M][M],n,m,ans,flag;
int a[5]={0,0,0,1,-1};
int b[5]={0,-1,1,0,0};
char cc;
int out(int x,int y)
{
if(x>n||x<1||y>m||y<1)return 1;
if(map[x][y]!=cc||vis[x][y])return 1;
return 0;
}
void dfs(int x,int y)
{
if(out(x+1,y)&&out(x,y+1)&&out(x-1,y)&&out(x,y-1))
return;
for(int i=1;i<=4;i++)
{
int xx=x+a[i];
int yy=y+b[i];
if(!out(xx,yy))
{
ans++;
vis[xx][yy]=1;
dfs(xx,yy);
}
}
}
int main()
{
int x,y;
scanf("%d%d%d%d",&n,&m,&x,&y);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>map[i][j];
cc=map[x][y];
dfs(x,y);
printf("%d",ans);
return 0;
}