n,m=map(int,input().split()) lines = ''.join([input() for _ in range(n)]) print(lines.count("W"))