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 <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    while(true){
        int n,r; cin>>n>>r;
        if(n==0&&r==0)break;
        
        vector<int> a(n);
        REP(i,n)a[i]=i+1;
        reverse(a.begin(),a.end());
        
        REP(kai,r){
            stack<int> sta;
            int p,c; cin>>p>>c;
            REP(i,c)sta.push(a[i+p-1]);
            REP(i,c)a.erase(a.begin()+p-1);
            REP(i,c){
                a.insert(a.begin(),sta.top());
                sta.pop();
            }
            /*REP(i,a.size())cout<<a[i]<<" ";
            cout<<endl;*/
        }
        
        cout<<a[0]<<endl;
        
    }
    
    return 0;
}

C++: #include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    int n, r;
    while(true){
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        int p[r], c[r];
        rep(i, r) cin >> p[i] >> c[i];
        map<int, int> mp;
        for(int i = 1; i <= n; i++) mp[i] =  n + 1 - i;
        rep(i, r){
            const int P = p[i], C = c[i];
            int A[P + 1] = {0}, B[C + 1] = {0};
            loop(i, 1,  P) A[i] = mp[i];
            loop(i, 1 , C + 1) B[i] = mp[i + P - 1];
            loop(i, 1,  P + C){
                if(i <= C) mp[i] = B[i];
                else mp[i] = A[i - C];
            }
        }
        cout << mp[1] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t

bool loop(){
    int n,r;
    cin >> n >> r;
    vector<int> a;
    
    for(int i = 0 ; i < n ; i++ ){
        a.push_back(i+1);
    }
    if( n == 0 && r == 0 )return false;
    
    for(int i = 0 ; i < r; i++ ){
        int p,c;
        cin >> p >> c;
        p = n + 1 - (c+p);
        for(int j = 0 ; j < c ; j++ ){
            a.push_back(a[p]);
            a.erase(a.begin() + p);
        }
        /*
        for(int j = 0 ; j < n ; j ++ ){
            cout << a[j] << "\t";
        }
        cout << endl;*/
    }
    
    cout << a[n-1] << endl;
    
    return true;
}


int main(void){
    while(loop());
    return 0;
}

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

int main()
{
	int n, r, p, c;
	while (true) {
		cin >> n >> r;

		if (n == 0 && r == 0) {
			break;
		}

		vector<int> cards;
		for (int i = 1; i <= n; i++) {
			cards.push_back(i);
		}

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

			p = n - p - c + 1;
			for (int j = 0; j < c; j++) {
				cards.push_back(cards[p]);
				cout << "cards[p]=" << cards[p] << endl;
				cards.erase(cards.begin() + p);
			}
		}

		cout << cards.back() << '\n';
	}

	return 0;
}

C++: 
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
using ll = long long;

int n, r, a, b;
int t[100];
int u[100], size;
int main() {
	while (cin >> n >> r && n&&r) {
		for (int i = 0; i<n; i++)t[i] = n - i;
		for (int i = 0; i<r; i++) {
			cin >> a >> b;
			for (int j = 0; j<b; j++)u[j] = t[j + a - 1];
			for (int j = a - 2; j >= 0; j--)t[j + b] = t[j];
			for (int j = 0; j<b; j++)t[j] = u[j];
		}
		cout << t[0] << endl;
	}
	return 0;
}

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

using namespace std;

int N, R, p, c, i, j;
int A[N] = {};

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

C++: #include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main(){
  int n;
  int r;
  int a[100];
  int b[100];
  int p;
  int c;
  while(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++){
      cin >> p >> c;
      for(int j = p-1;j < p+c; j++){
        b[j-p+1] = a[j];//c block
      }
      for(int j = p-2;j >= 0;j--){
        a[j+c] = a[j];
      }
      for(int j = 0;j < c;j++){
        a[j] = b[j];
      }
      //cout << a[0] << a[1] << a[2] << a[3] << a[4] << endl;
    }
  cout << a[0] << endl;
  }
}

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

int main(){
int n;
int r;
cin >> n >> r;
while (n!=0 || r!=0){
vector<int> card(n+1);
for (int i = 0; i < n; i++){
card[i]=n-i;
}
for (int i = 0; i < r; i++){
int p;
int c;
cin >> p >> c;
for (int j = 0; j < c; j++){
int deletenumber;
deletenumber = card[c+p-2];
card.erase(card.begin() + c+p-2);
card.insert(card.begin(),deletenumber);
}
}
cout << card[0] << endl;
cin >> n >> r;
}
}

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

#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define REP(i,k,N) for(int i=k;i<(int)(N);i++)
#define rrep(i,N) for(int i=N-1;i>=(int)0;i--)

#define vi vector<int>
#define pb push_back

int main(){
//    ifstream in("a_in.txt");
//    cin.rdbuf(in.rdbuf());

    int n,r;
    int cd[51];
    int p,c;
    int tmp[51];
    while(cin>>n>>r,n!=0){
        rep(i,n){
            cd[i]=n-i;
        }
        rep(i,r){
            cin >> p >>c;
            rep(j,c){
                tmp[j]=cd[p+j-1];
            }
            rrep(j,p){
                cd[j+c-1] = cd[j-1];
            }
            rep(j,c){
                cd[j]=tmp[j];
            }

        }
        cout << cd[0] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
  int n, r;
  while(cin >> n >> r, n || r){
    int deck[50];
    for(int i = 0; i < n; i++) deck[i] = n - i;
    while(r--){
      int p, c;
      cin >> p >> c;
      --p;
      int tmp[50];
      for(int i = 0; i < c; i++) tmp[i] = deck[p + i];
      for(int i = p + c - 1; i > 0; i--) deck[i] = deck[i-1];
      for(int i = 0; i < c; i++) deck[i] = tmp[i];
    }
    cout << deck[0] << endl;
  }
  return 0;
}