#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
int H,L,ans=0;
char p[110][110];
int x[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};
void dfs(int h,int l){
p[h][l]='.';
for(int i=0;i<8;i++){
int hh=h+x[i][0],ll=l+x[i][1];
if(hh>=0&&hh<H&&ll>=0&&ll<L&&p[hh][ll]=='W'){
dfs(hh,ll);
}
}
}
int main(){
scanf("%d%d",&H,&L);
for(int i=0;i<H;i++){
for(int j=0;j<L;j++){
scanf(" %c",&p[i][j]);
}
}
for(int i=0;i<H;i++){
for(int j=0;j<L;j++){
if(p[i][j]=='W'){
ans++;
dfs(i,j);
}
}
}
cout<<ans;
return 0;
}