from collections import deque
grid=[(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
m,n=map(int,input().split())
b=[input() for i in range(m)]
v=[[False]*n for k in range(m)]
count=0
l=deque()
for i in range(m):
for j in range(n):
if b[i][j]=='W' and v[i][j]==False:
count+=1
l.append((i,j))
while l:
s,t=l.popleft()
for x,y in grid:
if ((m-1)>=(s+x)>=0 and (n-1)>=(t+y)>=0 and b[s+x][t+y]=='W'
and v[s+x][t+y]==False):
v[s+x][t+y]=True
l.append((s+x,t+y))
print(count)

京公网安备 11010502036488号