w,h,i,j,f[52][52],d[8]={0,1,1,1,0,-1,-1,-1};rec(x,y,k){if(!f[x][y])return 0;for(f[x][y]=0;k-->0;)rec(x+d[k],y+d[(k+6)%8],8);return 1;}main(n){while(scanf("%d%d",&w,&h),w|h){for(j=1;j<=h;f[w+1][j++]=0)for(i=1;i<=w;f[i++][h+1]=n=0)scanf("%d",&f[i][j]);for(j=1;j<=h;j++)for(i=1;i<=w;)n+=rec(i++,j,8);printf("%d\n",n);}}