eolymp
bolt
Try our new interface for solving problems
Problems

Computer Vision

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 \textbf{N}×\textbf{M} cells. Each cell has number \textbf{1} if a bacteria part is detected, and number \textbf{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. \InputFile First line contains two natural numbers \textbf{N} and \textbf{M} (\textbf{1} ≤ \textbf{N}, \textbf{M} ≤ \textbf{1000}). Next \textbf{N} lines contain \textbf{M} digits each, NOT separated by spaces. The digits are \textbf{0} or \textbf{1}. \OutputFile Output the quantity of bacteries on the photo.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
4 5
00101
11011
01000
10111
Output example #1
5
Author Плоткин Артем
Source Osipovsky Cup - 2013