#include
#include
using namespace std;
struct node{
int s,t,c;
struct node *l,*r;
node(){
c=0;
l=r=NULL;
}
};
struct node *h;
int m,n;
int c_sum[100010];
void create_tree(struct node *x){
struct node *p,*q;
int mid;
if(x->t-x->s<=1)return ;
mid=(x->s+x->t)/2;
p=new node;
p->s=x->s;p->t=mid;
q=new node;
q->s=mid;q->t=x->t;
x->l=p;x->r=q;
create_tree(x->l);
create_tree(x->r);
return ;
}
void color(struct node *x,int u,int v,int z){
if(x==NULL)return ;
if(x->s==u && x->t==v){
x->c=z;
return ;
}else{
if(x->c!=-1){
x->l->c=x->c;
x->r->c=x->c;
x->c=-1;
}
if(u>=x->r->s)
color(x->r,u,v,z);
else if(v<=x->l->t)
color(x->l,u,v,z);
else{
color(x->l,u,x->l->t,z);
color(x->r,x->r->s,v,z);
}
}
}
void count(struct node *x){
if(x==NULL)return ;
if(x->c!=-1){
c_sum[x->c]+=x->t-x->s;
return ;
}
else{
count(x->l);
count(x->r);
}
return ;
}
int main(){
int i,j,k,m,n;
cin>>m>>n;
h=new node;
h->s=0;h->t=m;
create_tree(h);
int x,y;
for(i=1;i<=n;i++){
cin>>x>>y;
color(h,x,y,i);
}
count(h);
for(i=0;i<=n;i++)
if(c_sum[i])
cout<
return 0;
}