14466 - Counting herds   

Description

Elephants are social animals, and for them, adjacent elephants are considered part of the same herd (diagonal adjacency does not count). In other words, if an elephant is located at coordinates (x, y), then the elephants at (x+1, y)(x-1, y)(x, y+1), and (x, y-1) belong to the same herd.

Given a map of size n*m, where # represents an elephant and . represents an empty space, the task is to determine the total number of herds.

 

Sample:

.#.#.
####.
##..#
....#
##.##

Input

The first line contains two integers, n and m.

1 ≤ n, m ≤ 1000

The following n lines each contain a string of length m, where each character is either # or ..

Output

Output the number of herds.

Note that you do NOT need to print '\n' at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss