N,M = map(int,input().split()) L = [] for i in range(N) : a = input() L.append(a) L = ''.join(L) print(L.count("W"))