Number of Islands

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a map of land and sea made up of square cells. Write a program that counts the number of islands.

From any cell you may walk to a cell that is adjacent horizontally, vertically, or diagonally. In other words, each cell is connected to up to 8 neighboring cells.

Two land cells belong to the same island if there is a path that walks from one to the other while stepping only on land cells. The map is surrounded by sea, and you cannot move outside the map.

Input

The input consists of several test cases. The first line of each test case contains the width $w$ and the height $h$ of the map. $w$ and $h$ are positive integers not greater than $50$.

The next $h$ lines describe the map, each line containing $w$ integers separated by spaces. $1$ denotes land and $0$ denotes sea.

The last line of the input contains two zeros; this line is not processed.

Output

For each test case, print the number of islands, one per line.