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 "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int dy[] = { 0, 0, 1, -1 };
int dx[] = { 1, -1, 0, 0 };

ll A, B, C, D, E, F, G, H, I, J, K, L, M,
N, O, P, Q, R, S, T, U, V, W, X, Y, Z;

void aojHanafudaShuffle();
int main()
{
	aojHanafudaShuffle();
	return 0;
}

void aojHanafudaShuffle()
{
	N = R = 1;
	while (true) {
		cin >> N >> R;
		if (N == 0 and R == 0) break;

		vector<ll> cards(N);
		REP(i, N) cards[i] = i + 1;

		REP(i, R) {
			cin >> P >> C;
			vector<ll> tmp(C);
			copy(cards.begin() + (N - (C + P - 1)), cards.begin() + N - (P - 1), tmp.begin());
			copy(cards.begin() + (N - (P - 1)), cards.end(), cards.begin() + (N - (C + P - 1)));
			copy(tmp.begin(), tmp.end(), cards.begin() + (N - C));
		}

		cout << cards[cards.size() - 1] << endl;
	}
}

C++: // ・AOJ1142(setの練習問題)
// ・AOJ1129(vectorの練習問題)
// ・AOJ10032(stackの練習問題)
// ・AOJ10027(stringの練習問題)
// ・AOJ10021(sort || priority_queueの練習問題)
// ・AOJ1064(オーバーロードの練習問題)
// ・AOJ0138(mapの練習問題)
// ・AOJ0105(mapの練習問題)
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
	int n, r, p, c;
	vector<int> v;
	vector<int>::iterator ite;
	while(1){
		scanf("%d%d", &n, &r);
		if(n ==0 && r == 0) break;
		for (int i=1; i<=n; i++) { v.push_back(i); }
		for (int i=0; i<r; i++) {
			scanf("%d%d", &p, &c);
			ite = v.end()-p-c+1;
			for(int j=0; j<c; j++) {
				v.push_back(*ite);
				v.erase(ite);
			}
		// vector<int>::iterator test;
		// test = v.begin();
		// while(test != v.end()){printf("%d", *test); test++;}
		// printf("\n");
		}
		ite = v.end()-1;
		printf("%d\n", *ite);
	}
}

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

using namespace std;


int main(){

  int n,r,p,c;
  vector<int> y,P,C;

  while(true){
    cin >> n >>r;
    if(n+r==0) break;

    y.clear();
    y.resize(n);
    for(int i=0; i<y.size(); ++i){
      y[i]=i+1;
    }
    
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      
      P.clear();
      P.resize(y.size()-p);
      C.clear();
      C.resize(c);
      
      for(int k=0; k<P.size(); ++k){
	P[k]=y[k+p];
      }
      
      for(int k=0; k<C.size(); ++k){
	C[k]=y[k+p-c];
      }

      for(int k=0; k<P.size(); ++k){
	y[k+p-c]=P[k];
      }
      
      for(int k=0; k<C.size(); ++k){
	y[y.size()-c]=C[k];
      }

 
    }

    cout << y[y.size()-1] << endl;
  }

  
  return 0;
}

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

int main(void){
int n,r;
int p,c;
while(true){
cin>>n>>r;
if(n==0&&r==0)return 0;
vector<int> ca(n);
vector<int> t(n,0);
vector<int> t2(n,0);
for(int i=0;i<n;i++)ca[i]=n-i;
for(int i=0;i<r;i++){
	cin>>p>>c;
	for(int j=0;j<c;j++){
		t[p-1+j]=ca[p-1+j];
	}
	for(int k=0;k<p-1;k++){
		t2[c+k]=ca[k];
	}
	for(int k=0;k<p-1;k++){
		ca[c+k]=t2[c+k];	
	}
	for(int j=0;j<c;j++){
		ca[j]=t[p-1+j];
	}
}
cout<<ca[0]<<endl;
}
return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
using namespace std;

typedef vector<int> Ivec;

int main() {
	int n, r;

	while (scanf("%d %d", &n, &r)) {
		if (n == 0) 
			return 0;

		Ivec fuda;
		for (int i = n; 0 < i; i--)
			fuda.push_back(i);

		int p, c;
		for (int i = 0; r > i; i++) {
			scanf("%d %d", &p, &c);
			Ivec buf(fuda);
			for (int j = 0; c > j; j++) {
				fuda.insert(fuda.begin()+j, buf[p-1+j]);
			}
		}
		printf("%d\n", fuda[0]);
	}
	return 0;
}

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

int erase_alt(list<int> &lis, list<int>::iterator itr)
{
	int temp = *itr;
	lis.erase(itr);
	return temp;
}

int main()
{
	while (true)
	{
		list<int> list0;
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		for (int i=n; i > 0; i--)
		{
			list0.push_back(i);
		}
		for (int i = 0; i<r; i++)
		{
			int p, c;
			list<int>::iterator itr = list0.begin();
			cin >> p >> c;
			if (p == 1)continue;
			advance(itr, p - 1);
			list0.splice(list0.begin(), list0, itr, next(itr, c));
		}
		cout << *list0.begin() << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void){
	int p, c, count, n, r, huda[200] = {0}, i, j,an[100],a=0;
	while (1) {
		scanf("%d %d", &n, &r);
		for (i = 0;i < n;i++) {
			huda[i] = i + 1;
		}
		if (n == 0 && r == 0) {
			break;
		}
		for (i = 0;i < r;i++) {
			scanf("%d %d", &p, &c);

			for (j = 0;j < c;j++) {
				huda[n + j] = huda[n - p];
				huda[n - p] = -1;
			}

			count = 0;
			for (j = 0;j < n;j++) {

				if (count > n)
					break;
				huda[j] = huda[count];
				if (huda[count] == -1) {
					j--;
				}
				count++;

			}

		}
		an[a] = huda[n - 1];
		a++;
	}
	for (i = 0;i < a;i++) {
		printf("%d\n", an[i]);
	}

	return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,r;
	
	while(cin >> n >> r , n){
		int card[n],t[n];
		rep(i,n)card[n-i-1]=i+1;

		rep(i,r){
			rep(j,n)t[j] = card[j];
			int p,c;
			cin >> p >> c;
			rep(j,c)t[j] = card[p-1+j];
			rep(j,p)t[c+j] = card[j];
			rep(j,n)card[j] = t[j];
		}
		cout << card[0] << endl;
	}
}

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

int main()
{
	while (true) {
		int n, r;
		int cards[50];

		cin >> n >> r;

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

		for (int i = 0; i < 50; i++) {
			int temp = max(0, n - i);
			cards[i] = temp;
		}

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

			cin >> p >> c;

			vector<int> shuffle;

			for (int j = 0; j < c; j++) {
				shuffle.push_back(cards[p - 1 + j]);
			}

			for (int j = p - 2; j >= 0; j--) {
				cards[c + j] = cards[j];
			}
			
			for (int j = 0; j < c; j++) {
				cards[j] = shuffle[j];
			}
		}

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

	return 0;
}

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

int main(){
	while(1){
		int n,r;
		cin>>n>>r;
		if(n==0&&r==0)break;
		vector<int> a(n);
		for(int i = 0;i<n;i++){
			a[i]=n-i-1;
		}
		for(int i = 0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<n;j++){
				if(a[j]<p-1){
					a[j]+=c;
				}else if(a[j]<p+c){
					a[j]-=(p-1);
				}
			}
		}
		//cout<<"a"<<endl;
		for(int i=0;i<n;i++){
			if(a[i]==0)cout<<i+1<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r,c,p;
    vector<int> s,s2;
    cin >> n >> r;
    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 << s[i] << "  ";
        }
        cout << endl;
        s2.clear();
    }
    cout << s[n-1] << "\n";
}