"The zombies are lurking outside. Waiting. Moaning. And when they come..."

"When they come?"

"I hope the Wall is high enough."

Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segments. We call on you for help. Go forth and explore the wall! Report how many disconnected segments there are.

The wall is a two-dimensional structure made of bricks. Each brick is one unit wide and one unit high. Bricks are stacked on top of each other to form columns that are up to R bricks high. Each brick is placed either on the ground or directly on top of another brick. Consecutive non-empty columns form a wall segment. The entire wall, all the segments and empty columns in-between, is C columns wide.


-----Input-----

The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows:   each of the R lines contains a string of length C,  the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise.  The input will contain at least one character B and it will be valid.


-----Output-----

The number of wall segments in the input configuration.


-----Examples-----
Input
3 7
.......
.......
.BB.B..

Output
2

Input
4 5
..B..
..B..
B.B.B
BBB.B

Output
2

Input
4 6
..B...
B.B.BB
BBB.BB
BBBBBB

Output
1

Input
1 1
B

Output
1

Input
10 7
.......
.......
.......
.......
.......
.......
.......
.......
...B...
B.BB.B.

Output
3

Input
8 8
........
........
........
........
.B......
.B.....B
.B.....B
.BB...BB

Output
2



-----Note-----

In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second.

Difficulty: interview

Starter code:

Solutions:
n, m = map(int, input().split())
a = [input() for i in range(n)]
ans = 0
i = 0
while i < m:
    if a[n-1][i] == "B":
        ans += 1
        while i < m and a[n-1][i] == "B":
            i += 1
    i += 1

print(ans)

r, c = list(map(int, input().split()))

for _ in range(r-1):
    input()

bottom = input()

sections = 0

looking_for_new_section = True


for brick in bottom:
    if looking_for_new_section:
        if brick == 'B':
            looking_for_new_section = False
            sections += 1
    else:
        if brick == '.':
            looking_for_new_section = True

print(sections)


import sys, math
n,m = list(map(int,input().split()))
for i in range(n-1):
    input()
w=input()
w+='.'
ans = 0
now=1
for i in w:
    if i == 'B':
        if now:
            now = 0
            ans+=1
        else:
            continue
    else:
        now = 1
print(ans)


from sys import stdin as fin, setrecursionlimit as srl
# fin = open("hcc2016d1.in", "r")
debug = False

def process():
    r, c = list(map(int, fin.readline().split()))
    emp = [True] * c
    for j in range(r):
        row = fin.readline().rstrip()
        for i in range(c):
            if row[i] == 'B':
                emp[i] = False
    prev, cnt = True, 0
    for i in range(c):
        if prev and not emp[i]:
            cnt += 1
        prev = emp[i]
    print(cnt)
# fin.readline()
# process()
if not debug:
    process()
else:
    while fin.readline().strip() == '':
        process()
        print("----------------------------")


R, C = list(map(int, input().split()))
line = '.' * (C+2)
wall = [line]
for _ in range(R):
    wall.append('.' + input() + '.')
wall.append(line)

vs = set()
ans = 0


def visit(r, c):
    q = [(r, c)]
    while q:
        r, c = q.pop()
        if (r, c) in vs:
            continue
        vs.add((r, c))
        if wall[r-1][c] == 'B':
            q.append((r-1, c))
        if wall[r+1][c] == 'B':
            q.append((r+1, c))
        if wall[r][c-1] == 'B':
            q.append((r, c-1))
        if wall[r][c+1] == 'B':
            q.append((r, c+1))

for r in range(1, R+1):
    for c in range(1, C+1):
        if wall[r][c] == 'B' and (r, c) not in vs:
            ans += 1
            visit(r, c)

print(ans)


read = lambda: list(map(int, input().split()))
n, m = read()
a = [input() for i in range(n)]
s = a[n - 1].split('.')
cnt = len(s) - s.count('')
print(cnt)


n,m=map(int,input().split())
for i in range(n):
    k=input()
f=1
ans=0
for i in k:
    if i=='B' and f:
        ans+=1
        f=0
    if i=='.':
        f=1
print(ans)

r, c = list(map(int, input().split()))

last = ""
for i in range(r):
    s = str(input())

    if i == r - 1:
        last = s


answer = 0
left = 0

while left <= c - 1:
    if last[left] == "B":
        try:
            while last[left] == "B":
                left += 1
        except Exception:
            pass
        answer += 1
    else:
        left += 1


print(answer)



# 690 D1
r,c = [int(i) for i in input().split()]
for i in range(r-1):
	input()
s = input()
segs = 0
prev = '.'
for x in s:
	if x=='B' and prev =='.':
		segs += 1
	prev = x
print(segs)


import sys, math
n,m = list(map(int,input().split()))
for i in range(n-1):
    input()
w=input()
w+='.'
anc = 0
now=1
for i in w:
    if i == 'B':
        if now:
            now = 0
            anc+=1
        else:
            continue
    else:
        now = 1
print(anc)


r,c=[int(i) for i in input().split()]
for i in range(r-1):
    input()
s=input()
for i in range(c):
    s=s.replace('BB','B')
print(s.count('B'))


inc=input().split(' ')
for i in range(int(inc[0])):
    foundation = input()
bl=True
block=0
for i in range(int(inc[1])):
    if bl and foundation[i] == 'B':
        bl=False
        block+=1
    elif (not bl) and foundation[i] == '.':
        bl=True
print (block)

x=input().split()
r=int(x[0])
mas=""
for i in range(r):
     if i+1==r:
        mas=input()
        mas=mas+"."
        mas="."+mas
     else:
      input()
g=0
for i in range(len(mas)-1):
   if mas[i]!=mas[i+1]:
       g=g+1
print(int(g/2))

rc = input()
rc = rc.split()

r = int(rc[0])
c = int(rc[1])

for i in range(r):
	row = input()

count=0
for i in range(len(row)):
	 if(row[i] == 'B' and (i==0 or row[i-1]=='.')):
	 	count+=2
	 if(row[i] == 'B' and (i==len(row)-1 or row[i+1]=='.')):
	 	count-=1
	 
print (count)


n, m = list(map(int, input().split()))
a = [input() for _ in range(n)]
used = [[False] * m for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(m):
        if not used[i][j] and a[i][j] == "B":
            ans += 1
            q = [(i, j)]
            used[i][j] = True
            head = 0
            while head < len(q):
                x, y = q[head]
                head += 1
                for d in range(4):
                    xx = x + (1 if d == 0 else -1 if d == 1 else 0)
                    yy = y + (1 if d == 2 else -1 if d == 3 else 0)
                    if 0 <= xx < n and 0 <= yy < m and not used[xx][yy] and a[xx][yy] == "B":
                        used[xx][yy] = True
                        q.append((xx, yy))
print(ans)


import sys
#with open(filename, 'r') as f:
with sys.stdin as f:
    input_list = list(f)
for i, line in enumerate(input_list):
    if i == 0:
        R = int(line.split(" ")[0])
    else:
        if i == R:
            nb_walls = len(list(filter(lambda x: len(x) > 0, line.strip().split('.'))))
            print(nb_walls)

r,c=[int(i) for i in input().split()]
for i in range(r-1):
    input()
s=input()
for i in range(c):
    s=s.replace('BB','B')
print(s.count('B'))

r, c = input().split()
for q in range(int(r)): s = input() + '.'
print(s.count('B.'))

mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from itertools import groupby
n,m=f()
cnt=0
x=''
for i in range(n):
    x=si()
c=0
for i,j in groupby(x):
    c+=(i=='B')
print(c)

n,m = list(map(int,input().split()))
c = []
for i in range(n):
    a = list(input())
l = 0
for i in range(len(a)-1):
    if(a[i]=='B' and a[i+1]=='.'):
        l+=1
if(a[-1]=='B'):
    l+=1
print(l)


n, m = list(map(int, input().split()))
a = ''
for _ in range(n):
    a = input()
ans = 0
i = 0
while i < m:
    if 'B' == a[i]:
        ans += 1
        while i < m and 'B' == a[i]:
            i += 1
    else:
        i += 1
print(ans)


r, c = map(int, input().split())

for i in range(r-1):
	s = input()
s = input()

x = 0
cnt = 0
for i in range(c):
	if s[i] == "B":
		x += 1
	else:
		if x > 0:
			cnt += 1
		x = 0
if x > 0:
	cnt += 1
print (cnt)

r,c=list(map(int,input().split()))
a=[]
for i in range(r):
    a.append(input())
b=[]
for i in range(c):
    e=0
    for j in range(r):
        if a[j][i]=="B":
            e=1
    b.append(e)
d=0
e=0
for i in range(c):
    if b[i]==1:
        d+=1
    if b[i]==0 and d!=0:
        d=0
        e+=1
if d!=0:
    print(e+1)
else:
    print(e)