#include <stdio.h>

#define WIDTH_MAX 50
#define HEIGHT_MAX 50

int field[ WIDTH_MAX + 2 ][ HEIGHT_MAX + 2 ];
const int dx[ 8 ] = { -1, 0, 1, -1, 1, -1, 0, 1 }, dy[ 8 ] = { -1, -1, -1, 0, 0, 1, 1, 1 };

void del( int x, int y );

int main( void ) {
	int w, h, x, y, sum;

	for ( ; scanf( "%d %d", &w, &h ), w + h; printf( "%d\n", sum ) ) {
		for ( y = 1; y <= h; y++ )
			for ( x = 1; x <= w; x++ )
				scanf( "%d", field[ x ] + y );

		sum = 0;
		for ( y = 1; y <= h; y++ )
			for ( x = 1; x <= w; x++ )
				if ( field[ x ][ y ] == 1 ) {
					del( x, y );
					sum++;
				}

	}

	return 0;
}

void del( int x, int y ) {
	int i;

	field[ x ][ y ] = 0;

	for ( i = 0; i < 8; i++ ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ] == 1 )
			del( nx, ny );
	}
}	