ll@n,@m,a[m]{},c[m]{},d[n]{},b[m][n],z=0;rep(i,n){rep(j,m){ll@r;if(r>=a[j]){if(r>a[j])a[j]=r,z-=!--d[b[j][0..c[j]-1]],c[j]=0;z+=!d[b[j][c[j]++]=i]++;}}wt(z);}