Computer Vision
Biologist Alexander woke up early in the morning and came up to his microscope to check out how many bacteries had been born. He was shocked, there were too many bacteries, so that he could not count them.
Alexander sees a rectangle with N×M cells. Each cell has number 1 if a bacteria part is detected, and number 0 if no bacteria parts in the cell. One bacteria is an area of several interconnected cells, where that bacteria is detected. Two cells are interconnected if they have a common side.
Alexander made a photo of what he saw, and sent to us via e-mail. Please, write a program, that counts bacteries on the photo.
Input
First line contains two natural numbers N and M (1 ≤ N, M ≤ 1000). Next N lines contain M digits each, NOT separated by spaces. The digits are 0 or 1.
Output
Output the quantity of bacteries on the photo.