"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.

Source: codeforces | Difficulty: EASY


Solutions:
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)


from sys import *
print((stdin.read().split()[-1] + '.').count('B.'))


(n, m) = map(int, input().split(' '))
a = []
for x in range(n):
	t = list(input())
	a.append(t)
count = 1
chk = 1
x = 0
while x < m:
	if x == 0:
		while x < m and a[n - 1][x] == '.':
			x = x + 1
	while x < m and a[n - 1][x] == 'B':
		x = x + 1
	if x >= m:
		break
	while x < m and a[n - 1][x] == '.':
		x = x + 1
	if x >= m:
		break
	count = count + 1
print(count)


from sys import stdin as fin, setrecursionlimit as srl
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)
if not debug:
	process()
else:
	while fin.readline().strip() == '':
		process()
		print('----------------------------')


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)


(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)


(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)


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))


(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)


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'))


(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 = int(input().split()[0])
for i in range(r - 1):
	trash = input()
print((input().strip('.') + '.').count('B.'))


(r, c) = list(map(int, input().split()))
for i in range(r):
	a = input()
b = 0
z = 0
for j in range(c):
	if a[j] == 'B':
		if z == 0:
			b += 1
		z = 1
	else:
		z = 0
print(b)


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


(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
	elif brick == '.':
		looking_for_new_section = True
print(sections)


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)


(r, c) = 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)


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


(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)


(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) = [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)


(r, c) = [int(s) for s in input().split()]
w = []
for i in range(r):
	w.append(input())
count = 0

def isEmpty(i):
	for j in range(r):
		if w[j][i] == 'B':
			return False
	return True
started = False
for i in range(c):
	if not (isEmpty(i) or started):
		started = True
		count += 1
	if isEmpty(i):
		started = False
print(count)


(h, w) = list(map(int, input().split()))
arr = []
for i in range(h):
	arr.append(input())
c = 0
d = arr[h - 1].split('.')
for i in range(len(d)):
	if d[i] != '':
		c += 1
print(c)


(n, k) = map(int, input().split())
rows = []
for row in range(n):
	rows.append(input())
seg = []
ind = []
for i in range(n):
	for j in range(k):
		if rows[i][j] == 'B':
			ind.append(j)
for i in range(min(ind), max(ind) + 1):
	c = 0
	for j in rows:
		if j[i] == '.':
			c += 1
		c -= 1
	if c == 0:
		seg.append(i)
seg.sort()
fin = 1
if len(seg) > 0:
	fin += 1
for i in range(1, len(seg)):
	if seg[i] - 1 == seg[i - 1]:
		continue
	else:
		fin += 1
print(fin)


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)


(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)