int a[1d7],h,w,r,d[1d7],e,j;ll p(ll i){i>=0&&a[i]?a[d[e++]=i]=0:0;}{rd(h,w,a(h*w));rep(i,h*w)for(r+=a[i],p(i);e;p(j+w),~j%w&&p(j+1),j%w&&p(j-1),j/w&&p(j-w))j=d[--e];wt(r);}