#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

ll n,r;

ll f(){
	if(r--){
		ll p,c;
		scanf("%lld%lld",&p,&c);
		ll temp=f();
		if(temp<=c    )return temp+p-1;
		if(temp<=c+p-1)return temp-c;
		else return temp;
	}
	return 1;
}

int main(){
	while(scanf("%lld%lld",&n,&r),n){
		printf("%lld\n",n+1-f());
	}
}
