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<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 <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define frep(i, m, n) for(int i = m;i < n;i++)
#define frepr(i, m, n) for(int i = m;i >= n;i--)
#define vsort(v) sort(v.begin(),v.end())
#define ll long long
#define inf 999999999
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vst;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef pair<int,P> PP;
typedef pair<ll,LP> LPP;

int main(){
    int n,r;
    while(cin >> n >> r && n*r!=0){
        vi card(n);
        rep(i,n)card[i]=n-i;
        rep(i,r){
            int p,c;
            cin >> p >> c;
            rotate(card.begin(),card.begin()+p-1,card.begin()+p+c-1);
        }
        cout << card[0] << endl;
    }

    return 0;
}

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

int N, R, p, c;

void show(vector<int> v){
    for (int i = 0; i < N; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

int main(){
    while (cin >> N >> R && N){
        vector<int> card(N);
        for (int i = 0; i < N; i++){
            card[i] = N - i;
        }
        //cout << "初期入力"<< endl;
        //show(card);

        for (int i = 0; i < R; i++){
            cin >> p >> c;
            rotate(card.begin(), card.begin()+p-1, card.begin()+p+c-1);
            //cout << i+1 << "回目のrotate" << endl;
            //show(card);
        }
        cout << card[0] << endl;
    }
}

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

int main()
{
    int N, R, p, c;

    vector<int>v, buf1, buf2;

    while (cin >> N >> R&&N) {
        v.clear();
        for (int i = 1; i <= N; i++)
            v.push_back(i);

        for (int i = 0; i < R; ++i) {
            cin >> p >> c;
            buf1.clear();
            buf2.clear();
            for (int j = 0; j < v.size(); j++) {
                if (j < N - p - (c - 1) || N - p < j) {
                    buf1.push_back(v[j]);
                }
                else {
                    buf2.push_back(v[j]);
                }
            }v.clear();
            for (int j = 0; j < buf1.size(); j++) {
                v.push_back(buf1[j]);
            }
            for (int j = 0; j < buf2.size; j++) {
                v.push_back(buf2[j]);
            }
        }
        cout << v[v.size() - 1] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define dump(x) cout << #x << " = " << x << endl

using namespace std;

int card[50];
int n, r;

int main(){

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

		rep(i,0,n) card[i] = n - i;

		rep(i,0,r){
			int p, c;
			cin >> p >> c;
			int temp[p];

			rep(i,0,p) temp[i] = card[i];
			rep(i,0,c) card[i] = card[p-1 + i];
			rep(i,0,p) card[c + i] = temp[i];

		}

		cout << card[0] << endl;

	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int cards[50];

void shuffle(int p, int c) {
    int a[p + c - 1];
    for (int i = 0; i < p + c - 1; ++i) {
        if (i < c) {
            a[i] = cards[p - 1 + i];
        } else {
            a[i] = cards[i - c];
        }
    }

    for (int i = 0; i < p + c - 1; ++i) {
        cards[i] = a[i];
    }
}

int main() {
    while (true) {
        int N, R;
        cin >> N >> R;
        if (N == 0 && R == 0) return 0;

        for (int i = 0; i < N; ++i) {
            cards[i] = N - i;
        }

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

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

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

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int ans[1000];
int n,r,counter;
bool input(){
	for(int i=0;i<100;i++){
	x[i]=0;
	y[i]=0;
	}
	cin >>n>>r;
	for(int i=0;i<r;i++){
	cin>>x[i]>>y[i];
	}
	if(n==0){
	return false;
	}
	else{
	 return true;
	}
}
void solve(){
	for(int i=0;i<100;i++){
		card[i]=i+1;
	}
	for(int i=0;i<r;i++){
		for(int k=0;k<y[i];k++){
			int a=card[x[i]+y[i]-2];
			for(int j=x[i]+y[i]-1;j>0;j--){
				card[j]=card[j-1];
			}
			card[0]=a;
		}
	}
	ans[counter]=n-card[0]+1;
	counter++;
}



int main (){
	counter=0;
	while(input()){
	solve();
	}
	for(int i=0;i<counter;i++){
	cout<<ans[i]<<endl;
	}
return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

void swap(int *data,int p,int c){
	int *tmp;
	
	tmp = (int *)malloc(c*sizeof(int));

	for(int i = 0;i < c;i++){
		tmp[i] = data[p+i-1];
	}
	for(int i = p-2;i >= 0;i--){
		data[i+c] = data[i];
	}
	for(int i = 0;i < c;i++){
		data[i] = tmp[i];
	}
}

void show(int *data,int n){
	for(int i = 0;i < n;i++){
		printf("%d\n",data[i]);
	}
}

int main(){
	int n,r,p,c;
	int *data;

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

		data = (int *)malloc(n*sizeof(int));
		for(int i = 0;i < n;i++){
			data[i] = n-i;
		}

		//show(data,n);
		for(int i = 0;i < r;i++){
			scanf("%d %d",&p,&c);
			swap(data,p,c);
			//show(data,n);
		}

		printf("%d\n",data[0]);
	}

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

int main(){
  int n,r;
  while(cin >> n >> r, n){
    int npos[100];
    for(int i=0;i<n;i++){
      npos[i] = n-i;
    }
    for(int i=0;i<r;i++){
      int a,b;
      cin >> a >> b;
      int tmp[b];
      for(int j=0;j<b;j++){
	tmp[j] = npos[j+a-1];
      }
      for(int j=a+b-1;j>=b;j--){
	npos[j] = npos[j-b];
      }
      for(int j=0;j<b;j++){
	npos[j] = tmp[j];
      }
    }
    cout << npos[0] << endl;
  }
}