Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	} 

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]+1-c[i]-1)>=ans){
		}else if(ans>=(n-c[i]-1)){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	}
	printf("%d\n",ans);

	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(x) x.begin(),x.end()
#define ll long long
using namespace std;

void shuf(vector<int> &v,int p,int c){
    p-=1;
    vector<int> tmp1(p,0),tmp2(c,0);
    rep(i,p){
        tmp1[i]=v[i];
    }
    rep(i,c){
        tmp2[i]=v[p+i];
    }
    rep(i,c){
        v[i]=tmp2[i];
    }
    rep(i,p){
        v[c+i]=tmp1[i];
    }

}

int main(){
    while (true){
        int n,r;
        cin>>n>>r;
        if (n==0)
            break;
        vector<int> deck(n,0);
        rep(i,n){
            deck[n-i-1]=i+1;
        }
        rep(i,r){
            int p,c;
            cin>>p>>c;
            shuf(deck,p,c);
        }
        cout<<deck[0]<<endl;
    }

}

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-1,A+p+c-1);

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

C++: #include <iostream>
#include <algorithm>

#define range(i,a,b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)

using namespace std;

int a[110];

int main(void){
	int n,r;
	while(cin >> n >> r,n|r){
		rep(i,n) a[i]=n-i;
		//cout << a[0] << a[1] << endl;
		rep(i,r){
			int p,c;
			cin >> p >> c;
			int tmp[110];
			rep(i,p-1) tmp[i]=a[i];
			rep(i,c) a[i]=a[i+p-1];
			rep(i,p-1) a[i+c]=tmp[i];
		}
		cout << a[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    for(int n,r;cin>>n>>r,n;){
        vi cur(n);
        rep(i,n) cur[i] = n-i;
        rep(i,r){
            int p,c; cin >> p >> c;
            p--;
            vi next = cur;
            rep(i,c+p){
                next[i] = cur[(i+p)%(c+p)];
            }
            swap(cur,next);
        }
        cout << cur[0] << endl;
    }
}

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

int main(){
	while (true){
		int n, r,a[50];
		cin >> n >> r;
		if (n == 0 && r == 0){ break; }
		for (int i = 0; i < n; i++){
			a[i] = n-i;
		}

		for (int i = 0; i < r; i++){
			int p, c, b[50];
			cin >> p >> c;
			for (int j = 0; j < p-1; j++){
				b[j] = a[j];
			}
			for (int j = 0; j < c; j++){
				a[j] = a[p + j-1];
			}
			for (int j = 0; j < p-1; j++){
				a[c + j] = b[j];
			}
			cout << a[0] << endl;
		}

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

C++: 
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,j,n) for(int i = j; i < n; i++)


int main(){
	while(1){
		int n,r;
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}

		vector<int> m(n);
		rep(i,n){
			m[i] = n - i;
		}

		rep(i,r){
			int p, c;
			cin >> p >> c;
			vector<int> w;

			REP(i,p-1,p-1+c){
				w.push_back(m[i]);
			}

			REP(i,0,p-1){
				w.push_back(m[i]);
			}

			REP(i,p-1+c,n){
				w.push_back(m[i]);
			}
			m = w;
		}
		cout << m[0] << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

   while(1){

      int n, r;
      cin>> n>> r;
      if(n==0&&r==0) break;
      int a[n];
      for(int i=0; i<n; i++) a[i]=n-i;
      for(int i=0; i<r; i++){
         int p, c;
         cin>> p>> c;
         int b[c];
         for(int j=p-1; j<p+c-1; j++){
            b[j-(p-1)]=a[j];
         }
         for(int j=p+c-1; j>c-1; j--){
            a[j]=a[j-c];
         }
         for(int j=0; j<c; j++){
            a[j]=b[j];
         }
      }

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N, R, p, c;
    while (cin >> N >> R && N) {
        vector <int> A(N,0);
        for (int i = 0; i < N; ++i) A[i] = N - i;
        for (int i = 0; i < R; ++i) {
            cin >> p >> c;
            rotate(A.begin(), A.begin()+p-1,A.begin()+c+p-1);
        }
        cout << A[0] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#define rep(i,n) for(int i = 1 ; i <= n ; i++)

using namespace std;

int main()
{
  while(true){
    int n,r;
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    
    vector<int> card;
    rep(i, n){
      card.push_back(i);
    }
    int p,c;
    for( ; r > 0 ; r--){
      cin >> p >> c;

      p = n - p - c + 1;
      for( ; c > 0 ; c--){
	card.push_back(card[p]);
	card.erase(card.begin() + p);
      }
    }
    cout << card.back() << '\n';
  }
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[50];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int hanahuda[50];
		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){
		int nokori=hanahuda[k];
		for(int l=p-2;l>=0;l--){
			hanahuda[l+1]=hanahuda[l];
		}
		hanahuda[cnt]=nokori;
		cnt++;
	}

	return *hanahuda;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<fstream>

#define SIZE 50

using namespace std;

int main(){
	int kard[SIZE]	= {0};
	int n,k,p,c;

	while(cin>>n>>k,n){
		for(int i=0;i<n ;i++){
			kard[i]	=n-i;
		}
		for(int i=0; i<k; i++){
			cin>>p>>c;
			rotate(kard,kard+p-1,kard+p-1+c);
		}
		cout<<kard[0]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    while(1) {
        int n, r; cin >> n >> r;
        if(n==0 && r==0) break;

        vector<int> vec(n);
        rep(i, n) vec[i] = n-i;
        rep(i, r) {
            int p, c; cin >> p >> c;
            p--;
            int loc = 0;
            rep(j, c) {
                int num = vec[p];
                vec.erase(vec.begin()+p);
                vec.insert(vec.begin()+loc, num);
                p++;
                loc++;
            }
        }
        cout << vec.front() << endl;
    }
}