Skip to content
UPEEC

Copper Islands on a PCB

Medium#graphs#dfs#bfs#matrix· solved by 0 · time limit 2.0 s

A PCB is scanned as a grid: # is copper, . is bare board. Copper cells touching up, down, left or right belong to the same island. How many separate copper islands are there?

Input

RR and CC, then RR lines of CC characters.

Output

The number of islands.

Constraints

1≤R,C≤10001 \le R, C \le 1000

Sample 1

Input

4 5
##...
##...
..#..
...##

Output

3

Sign in or join free to run and submit your solution.