Banner

Count connected groups of 1s in an M by N grid where cells touching in any of the eight directions belong to the same group.

Easy3GraphDFSBFSImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

ANT hung a banner for the first programming contest it ever held.

Photo of the banner

Hyeokjin took an image processing course last semester and wants to put what he learned to use, so he is writing a program that counts how many letters the banner holds.

First he applied a filter that turns every part of the banner that belongs to a letter into 1 and every other part into 0.

Looking only at those values, he decided that whenever cells holding 1 touch each other up, down, left, right, or diagonally, the whole connected blob is one letter. In other words, the neighbors of a cell are the eight cells around it.

Given the values Hyeokjin produced with his filter, print how many letters his program counts.

Input

The first line holds the size of the banner, MM and NN. (1M,N2501 \le M, N \le 250)

Lines 2 through M+1M+1 hold the banner data. Each line holds NN values of one row, separated by spaces, and every value is 0 or 1.

Output

Print the number of letters counted the way Hyeokjin thinks of them.