Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n,r;
    int p,c;
    int move[55]={};
    int keep[55]={};
    while(1==1)
    {
        scanf("%d %d\n",&n,&r);
        REP(i,n)move[i]=n-i;
        if(n==0 && r==0)break;
        REP(i,r)
        {
            scanf("%d %d\n",&p,&c);
            REP(j,n)keep[j]=move[j];
            REP(j,c)move[j]=keep[j+p-1];
            for(int j=c;j<c+p-1;j++)move[j]=keep[j-c];
            //REP(j,n)printf("%d ",move[j]);
            //printf("###\n");
        }
        printf("%d\n",move[0]);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
struct num{
  int c,p;
};
std::vector<int> push(std::vector<int> recv,int p,int c){
  std::vector<int> vec;
  for(int i=p-1;i<=p+c-2;++i){
    vec.push_back(recv[i]);
  }
  return vec;
}
std::vector<int> cp(std::vector<int> recv,std::vector<int> recv2){
  std::vector<int> vec;
  for(int i=0;i<recv.size();++i){
    vec.push_back(recv[i]);
  }
  for(int i=0;i<recv2.size();++i){
    vec.push_back(recv2[i]);
  }
  return vec;
}
int main(){
    int n,r;
    while(std::cin>>n>>r,n!=0){
    std::vector<num> vec;
    std::vector<int> f;
    for(int i=0;i<n;++i){
      f.push_back(n-i);
    }
    for(int i=0;i<r;++i){
      num n;
      std::cin>>n.p>>n.c;
      vec.push_back(n);
    }
    for(int i=0;i<vec.size();++i){
      std::vector<int> vec2;
      vec2=push(f,vec[i].p,vec[i].c);
      f=cp(vec2,f);
    }
    std::cout<<f[0]<<std::endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n,r;
    int p,c;
    int move[55]={};
    int keep[55]={};
    while(1==1)
    {
        scanf("%d %d\n",&n,&r);
        REP(i,n)move[i]=n-i;
        if(n==0 && r==0)break;
        REP(i,r)
        {
            scanf("%d %d\n",&p,&c);
            REP(j,n)keep[j]=move[j];
            REP(j,c)move[j]=keep[j+p-1];
            for(int j=c;j<c+p-1;j++)move[j]=keep[j-c];
            REP(j,n)printf("%d ",move[j]);
            printf("###\n");
        }
        printf("%d\n",move[0]);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int n,r;
int p,c;
vector<int> card;
vector<int> tmp;
int main(){
  while(true){

    cin >> n >> r;
    if(n==0&&r==0)break;
    card.resize(n);
    REP(i,n)card[i]=i+1;
    REP(i,r){
      cin >> p >> c;
      for(int j=n-p+1;j<n-p+1+c;j++)
	tmp.push_back(card[j-c]);
      for(int j=n-p+1;j<n;j++){
    card[j-c] = card[j];
      }
      /*      REP(k,n)cout << card[k] << " ";
	      cout << "\n";*/
    if(p!=1)
      for(int j=n-c;j<n;j++)
        card[j] =tmp[j-n+c];
    /*      REP(k,n)cout << card[k] << " ";
	    cout << "\n";*/
      tmp.clear();
    }
    cout << card[n-1] << endl;
    card.clear();

  }

  return 0;
    
}

C++: #include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    int n, r;
    while(cin>>n>>r&&n){
        vector<int> line(n);
        REP(i, n)line[i]=n-i;
        REP(i, r){
            int p, c;
            cin >> p >> c;
            vector<int> nl(line.begin()+p-1, line.begin()+p+c-1);
            nl.insert(nl.end(), line.begin(), line.begin()+p-1);
            nl.insert(nl.end(), line.begin()+p+c-1, line.end());
            line=nl;
        }
        cout << line.front() << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rep_to(a,i,x) for(int i=a;i<x;i++)

using namespace std;

int main()
{
	int n,r;

	while(cin>>n>>r && n && r)
	{
		int card[100000]={};
		for(int i=n,j=1;i>=1;i--,j++)card[j]=i;
		rep(i,r)
		{
			int p,c;
			cin>>p>>c;
			for(int j=p;j>1;j--)
			{
				//cout<<j<<endl;
				for(int k=j;k<c+j;k++)
				{
					swap(card[k],card[k-1]);
					/*
					cout<<"swap:"<<k<<" "<<k-1<<endl;
					rep_to(1,l,n+1)cout<<card[l]<<" ";
					cout<<endl;
					*/
				}
			}
		}
		cout<<card[1]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int n, r;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0) return 0;
		int a[n] = {};
		for(int i=0; i<n; ++i)
			a[i] = n-i;
//		for(int i=0; i<n; ++i)
//			cout << a[i] << (i==n-1?"\n":" ");
		for(int i=0; i<r; ++i){
			int p, c;
			cin >> p >> c;
			int b[c] = {};
			for(int i=0; i<c; ++i)
				b[i] = a[p+i-1];
			for(int i=p-2; i>=0; --i)
				a[c+i] = a[i];
//			for(int i=0; i<n; ++i)
//				cout << a[i] << (i==n-1?"\n":" ");
			for(int i=0; i<c; ++i)
				a[i] = b[i];
//			for(int i=0; i<n; ++i)
//				cout << a[i] << (i==n-1?"\n":" ");
		}
		cout << a[0] << "\n";
	}
}

C++: #include <array>
#include <iostream>
#include <algorithm>
using namespace std;

int N,R,p,c;
int main() {
  while (cin >> N >> R && N) {
  array<int,50> A = {};
  for (int i=0;i<N;i++) {
    A[i] = N-i;
  }
  /*  for (int i=0;i<N;i++) {
    cout << A[i];
  }
  cout << endl; */
  for (int i=0;i<R;i++) {
    cin >> p >> c;
    rotate(A.begin(),A.begin()+p-1,A.begin()+p-1+c);
    /*    for (int i=0;i<N;i++) {
      cout << A[i];
    }
    cout << endl; */
  }
  cout << A[0] << endl;
}
}