You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map.

<image>
Figure B-1: A marine area map

You can walk from a square land area to another if they are horizontally, vertically, or diagonally adjacent to each other on the map. Two areas are on the same island if and only if you can walk from one to the other possibly through other land areas. The marine area on the map is surrounded by the sea and therefore you cannot go outside of the area on foot.

You are requested to write a program that reads the map and counts the number of islands on it. For instance, the map in Figure B-1 includes three islands.

Input

The input consists of a series of datasets, each being in the following format.

> w h
>  c1,1 c1,2 ... c1,w
>  c2,1 c2,2 ... c2,w
>  ...
>  ch,1 ch,2 ... ch,w
>

w and h are positive integers no more than 50 that represent the width and the height of the given map, respectively. In other words, the map consists of w×h squares of the same size. w and h are separated by a single space.

ci, j is either 0 or 1 and delimited by a single space. If ci, j = 0, the square that is the i-th from the left and j-th from the top on the map represents a sea area. Otherwise, that is, if ci, j = 1, it represents a land area.

The end of the input is indicated by a line containing two zeros separated by a single space.

Output

For each dataset, output the number of the islands in a line. No extra characters should occur in the output.

Sample Input


1 1
0
2 2
0 1
1 0
3 2
1 1 1
1 1 1
5 4
1 0 1 0 0
1 0 0 0 0
1 0 1 0 1
1 0 0 1 0
5 4
1 1 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 1 1
5 5
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1
0 0


Output for the Sample Input


0
1
1
3
1
9






Example

Input

1 1
0
2 2
0 1
1 0
3 2
1 1 1
1 1 1
5 4
1 0 1 0 0
1 0 0 0 0
1 0 1 0 1
1 0 0 1 0
5 4
1 1 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 1 1
5 5
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1
0 0


Output

0
1
1
3
1
9
import java.util.*;
public class Main{
     static int M,N;
        public static void main(String[] a)throws java.io.IOException{
            Scanner sc=new Scanner(System.in);
            while(sc.hasNextInt()){
                    N=sc.nextInt();
                    M=sc.nextInt();
                    if(N==0||M==0)break;
                    int ans =0;
                    int [][] fin =new int[M][N];
                    for(int i=0;i<M;i++){
                        for(int j=0;j<N ;j++){
                            fin[i][j] = sc.nextInt();
                        }
                    }
  
                    
                    
                    
                    for(int i=0;i<M;i++){
                        for(int j=0;j<N;j++){
                            if(fin[i][j] == 1){
                                ++ans;
                                temp(i,j,fin);
  
                            }
                        }
                    }
                    
                    
                    
                    
                    System.out.println(ans);
                    sc.nextLine();
            }
    }
  
  
          public static void temp(int y,int x,int [][] fin){
              fin[y][x] = 0;
              for(int i=-1;i<=1;i++){
                  for(int j=-1;j<=1;j++){
                  int n1 =x+j;
                  int n2 =y+i;
                  if(0<=n1 && n1< N &&0<=n2 && n2 <M &&fin[n2][n1]==1)
                      temp(n2,n1,fin);
                  }
              }
              return;
          }
}