# [霍尔定理] AtCoder Regular Contest 076 F Exhausted?

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#define pb push_back
using namespace std;

inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
}
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int N=200005;

int T[N<<2],F[N<<2];
inline void Build(int x,int l,int r){
if (l==r) return void(T[x]=l);
int mid=(l+r)>>1; Build(x<<1,l,mid); Build(x<<1|1,mid+1,r);
T[x]=max(T[x<<1],T[x<<1|1]);
}
inline void Add(int x,int l,int r,int ql,int qr){
if (ql<=l && r<=qr){
T[x]++; F[x]++; return;
}
int mid=(l+r)>>1;
T[x]=F[x]+max(T[x<<1],T[x<<1|1]);
}
inline int Query(int x,int l,int r,int ql,int qr){
if (ql<=l && r<=qr)
return T[x];
int mid=(l+r)>>1,ret=0;
if (ql<=mid) ret=max(ret,Query(x<<1,l,mid,ql,qr));
if (qr>mid) ret=max(ret,Query(x<<1|1,mid+1,r,ql,qr));
return ret+F[x];
}

int n,m;
vector<int> R[N];

int main(){
int x,y;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);