#include<bits/stdc++.h>
using namespace std;
int n,m,x1,z1,ans=0;
char a[10050][10050];
void dfs(int x,int y){
if(x>=n or x<0 or y>=m or y<0){
return;
}
if(a[x][y]=='*'){
return;
}
if(a[x][y]=='S'){
ans++;
}
if(a[x][y]=='M'){
ans+=5;
}
if(a[x][y]=='L'){
ans+=10;
}
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y+1);
dfs(x,y-1);
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
cin>>x1>>z1;
dfs(x1,z1);
cout<<ans;
}
https://www.luogu.com.cn/record/216515997