#include <iostream>
using namespace std;
int n,m,ans=0;
bool a[105][105];
const int f[][2]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,-1},{-1,1},{1,1}};
void dfs(int x,int y)
{
if(x>n||x<1||y>m||y<1)
return;
if(!a[x][y]&&x!=1&&y!=1)
return;
for(int i=0;i<8;i++)
if(a[x+f[i][0]][y+f[i][1]])
{
a[x][y]=false;
dfs(x+f[i][0],y+f[i][1]);
a[x][y]=true;
}
ans++;
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
char c;
cin>>c;
a[i][j]=c=='W'?true:false;
}
dfs(1,1);
cout<<ans<<endl;
return 0;
}