#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const pair&p){ os< ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os<>n>>m; int r[n][m]; rep(i,n)rep(j,m) cin>>r[i][j]; vector> c(m); vector mx(m,-1),cnt(n,0); int ans=0; rep(i,n){ rep(j,m){ if(mx[j]==r[i][j]){ c[j].push_back(i); if(cnt[i]==0) ans++; cnt[i]++; }else if(r[i][j]>mx[j]){ mx[j]=r[i][j]; while(c[j].size()){ cnt[c[j].back()]--; if(cnt[c[j].back()]==0) ans--; c[j].pop_back(); } if(cnt[i]==0) ans++; cnt[i]++; c[j].push_back(i); } } cout<