#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct DisjointSparseTable{ using F = function; vector > dat; vector ht; const F f; DisjointSparseTable(){} DisjointSparseTable(F f):f(f){} void build(const vector &v){ int n=v.size(),h=1; while((1<(n)); ht.assign((1<>1]+1; for(int j=0;j=j;k--) dat[i][k]=f(v[k],dat[i][k+1]); if(n<=t) break; dat[i][t]=v[t]; int r=min(t+s,n); for(int k=t+1;k=--r) return dat[0][l]; return f(dat[ht[l^r]][l],dat[ht[l^r]][r]); } }; //INSERT ABOVE HERE signed main(){ int n,m; cin>>n>>m; vector > r(m,vector(n)); for(int i=0;i>r[j][i]; auto f=[](int a,int b){return max(a,b);}; vector > ss; for(int j=0;j dp(n+1,0); for(int i=0;ir[j][i]) continue; int L=i,R=n; while(L+1>1; if(ss[j].query(0,M+1)>r[j][i]) R=M; else L=M; } chmax(s,R); } if(i<=s) dp[i]++,dp[s]--; } for(int i=0;i