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 <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll n,r; cin >> n >> r;
		if(n==0 && r==0) break;
		vl a(n); rep(i,n) a[i] = i+1;
		while(r--){
			ll p,c; cin >> p >> c;
			vl v;
			REP(i,n-p-c+1,n-p+1){
				v.push_back(a[i]);
			}
			a.erase(a.begin()+n-p-c+1,a.begin()+n-p+1);
			for(auto i : v) a.push_back(i);
		}
		cout << a[n-1] << endl;
	}
}

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

int main(){
    int card[51];
    int tmp[50];
    int n,r, from, num;
    int result[50], numres=0;

    while(1){
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        for(int i=1; i<=n; i++){
            card[i]=n-i+1;
        }
        for(int i=0; i<r; i++){
            cin >> from >> num;
            for(int j=0; j<num; j++){
                tmp[j] = card[from+j];
            }
            for(int j=from; j>0; j--){
                card[j+num] = card[j];
            }
            for(int j=0; j<num; j++){
                card[j+1] = tmp[j];
            }
        }
        result[numres] = card[1];
        numres++;
    }

    for(int i=0; i<numres; i++){
        cout << result[i] << endl;
    }
        
    return 0;
}

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

int main() {
int N,R,p,c;
while (cin>>N>>R&&N) { 
	int A[100]={};
	for(int i=0;i<N;i++){
		A[i]=i+1;
	}
	
	for (int i=0; i<R; ++i) {
	cin >> p >> c ;
	rotate(A,A+p,A+p+c);

 }
 cout << A[0] << endl;
 }
	return 0;
}

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

int N, R;
int S[50];

int main() {
  while (cin >> N >> R) {
    if (N == 0 && R == 0) break;
    for (int i=0; i<N; i++) S[i] = N-i;
    for (int i=0; i<R; i++) {
      int p, c;
      cin >> p >> c;
      vector<int> t;
      for (int i=p-1; i<p+c-1; i++) t.push_back(S[i]);
      for (int i=p-2; i>=0; i--) {
        S[i+c] = S[i];
      }
      for (int i=0; i<c; i++) S[i] = t[i];
    }
    cout << S[0] << "\n";
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r,c,p;
    vector<int> s,s2;
    while(1){
        cin >> n >> r;
        if(n==0&&r==0)  break;
        for(int i=1;i<=n;i++){
            s.push_back(i);
        }
        while(r--){
            cin >> p >> c;
            for(int i=0;i<n-c-p+1;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-p+1;i<n;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-c-p+1;i<n-p+1;i++){
                s2.push_back(s[i]);
            }
            s.clear();
            for(int i=0;i<n;i++){
                s.push_back(s2[i]);
            }
            cout << endl;
            s2.clear();
        }
        cout << s[n-1] << "\n";
        s.clear();
    }
}

C++: #include<iostream>
using namespace std;
int main(){

    int n,r;
    while(cin>>n>>r,n){
        int a[2][60];
        int now = 1;
        for(int i = 0;i < n;i++)a[0][i] = i;
        while(r--){
            int p,c;
            cin>>p>>c;
            p--;
            for(int i = p;i < p+c;i++){
                a[now][i-p] = a[1-now][i];
            }
            for(int i = 0,t = 0;i < n;i++){
                if(p<=i&&i<p+c)continue;
                a[now][t+c] = a[1-now][i];
                t++;
            }
            //for(int i = 0;i < n;i++)cout<<a[now][i]<<" ";
            //cout<<endl;
            now = 1-now;
        }
        cout<<n-1-a[1-now][0]+1<<endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    while(1){
        int n,r,num[51],p,c;
        cin >> n >> r;
        if(n==0&&r==0)  break;
        for(int i=1;i<=n;i++) num[i] = i;   
        for(int i=0;i<r;i++){
            cin >> p >> c;
            for(int j=p,x=n;j>=p-c;j--,x--){
                swap(num[j],num[x]);
            }
        }
        cout << num[n]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
	int n,r;
	while(cin>>n>>r,n) 
	{
		string deck="";
		for(int i = n; 0 < i; --i)
		{
			deck+='0'+i;
		}

		for(int i = 0; i < r; ++i)
		{
			int p,c; cin>>p>>c;

			string t="",m="",b="";
			t=deck.substr(0,p-1);
			m=deck.substr(p-1,c);
			b=deck.substr(p-1+c);

			deck=m+t+b;
		}
		cout<<deck[0]<<endl;
	}
  return 0;
}

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

typedef stack<int> S;

int main(void)
{
	int n, r;
	while (cin >> n >> r && n && r) {
		S s, s1, s2;
		int p, c;
		for (int i = 1; i < n+1; i++) s.push(i);
		for (int j = 0; j < r; j++) {
			cin >> p >> c;
			for (int i = 0; i < p-1; i++) {
				s1.push(s.top());
				s.pop();
			}
			for (int i = 0; i < c; i++) {
				s2.push(s.top());
				s.pop();
			}
			for (int i = 0; i < p-1; i++) {
				s.push(s1.top());
				s1.pop();
			}
			for (int i = 0; i < c; i++) {
				s.push(s2.top());
				s2.pop();
			}
		}
		cout << s.top() << endl;
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,r,p,c,i,j,a[51],b[51];
	while(1)	{
		scanf("%d %d",&n,&r);
		if(n==0 && r==0)	break;
		for(i=1;i<=n;i++)	{
			a[i]=n-i+1;
		}
		for(j=0;j<r;j++)	{
		
		//	for(i=1;i<=n;i++)	printf(" %d\n",a[i]);
		
			scanf("%d %d",&p,&c);
			for(i=1;i<=c;i++)	{
				b[i]=a[i+p-1];
			}
			for(i=c+1;i<c+p;i++)	{
				b[i]=a[i-c];
			}
			for(i=c+p;i<=n;i++)	{
				b[i]=a[i];
			}
			for(i=1;i<=n;i++)	{
				a[i]=b[i];
			}
		}
		printf("%d\n",a[1]);
	}
	return 0;
}