n,m = map(int, input().split()) list1 = [] anser = 0 for i in range(n): a = input() b = list(a) list1.append(b) for i in range(n): for i in range(m): if list1[n][m] == 'W': anser += 1 else: pass print(anser)