import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void fill(ref int[][] m, int x, int y) {
	if(m[x][y] == 1) {
		m[x][y] = 0;
		for(int i = -1; i <= 1; ++i) {
			for(int j = -1; j <= 1; ++j) {
				fill(m, x+i, y+j);
			}
		}  
	}
}

void main(){
	while(true){
		auto wh = readInts();
		auto w = wh[0];
		auto h = wh[1];
		if(w == 0) {
			return;
		}
		int[][] m;
		for(int i; i < h; ++i) {
			m ~= [0] ~ readInts() ~ [0];
		}
		m = [new int[](w+2)] ~ m;
		m ~= new int[](w+2);
		int ans;
		for(int i; i < h; ++i) {
			for(int j; j < w; ++j) {
				if(m[i+1][j+1] == 1) {
					++ans;
					fill(m, i+1, j+1);
				}
			}
		}
		writeln(ans);
	}
}