from collections import deque
def bfs(x,y):
q=deque()
q.append([x,y])
visited[x][y]=1
while q:
x,y=q.popleft()
for i in range(8):
nx,ny =x+dx[i], y+dy[i]
if 0<=nx<h and 0<=ny<w:
if lack[nx][ny]=='L' and visited[nx][ny]==0:
visited[nx][ny]=1
q.append([nx,ny])
global w, h
w, h = map(int, input().split())
global lack
lack=[]
for i in range(h):
lack.append(list(map(str,input().split())))
global dx, dy
dx=[0,0,1,-1,1,-1,1,-1]
dy=[1,-1,0,0,1,-1,-1,1]
cnt=0
global visited
visited=[[0 for x in range(w)] for y in range(h)]
for i in range(h):
for j in range(w):
if lack[i][j]=='L' and visited[i][j]==0:
bfs(i,j)
cnt+=1
print(cnt)