Counting Rooms


Submit solution

Points: 100
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

A grid cell is either floor . or wall #. Two floor cells belong to the same room when connected through shared sides. Count the rooms.

Input

The first line contains n and m. The next n lines contain the grid.

  • 1 <= n, m <= 1000

Output

Print the number of rooms.

Example

Input
5 8
########
#..#...#
####.#.#
#..#...#
########
Output
3

Comments

There are no comments at the moment.