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 <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.erase(fuda.begin()+p-1+j);
				fuda.insert(fuda.begin()+j, buf[p-1+j]);
			}
		}
		printf("%d\n", fuda[0]);
	}
	return 0;
}

C++: #include<string>
#include<vector>
#include<iostream>
 
using namespace std;
 
int main()
{
    int n, r;
    while(cin >> n >> r){
        if(n==0 && r==0) break;
        vector<int> huda;
        for(int i=0;i<n;i++){
            huda.push_back(n-i);
        }
        /*
		for(int i=0;i<n;i++){
            cout<<huda[i]<<endl;
        }
        cout<<endl;
		*/
        for(int i=0;i<r;i++){
            int p, c;
            cin >> p >> c;
            vector<int> temp;
            for(int j=0;j<c;j++){
				temp.push_back(huda[p-1+j]);
            }
            /*
			cout<<"temp"<<endl;
            for(int i=0;i<temp.size();i++){
                cout<<temp[i]<<endl;
            }
            cout<<endl;
            */
            for(int j=c-1;(p-1+j-c)>=0;j--){
				//cout << p-1+j << " " << p-1+j-c <<endl;
				huda[p-1+j]=huda[p-1+j-c];
			}
            //cout <<endl;
            for(int j=0;j<c;j++){
                huda[j]=temp[j];
            }
            /*
			for(int i=0;i<n;i++){
				cout<<huda[i]<<endl;
			}
	        cout <<endl;
			*/
        }
        /*
        for(int i=0;i<n;i++){
            cout<<huda[i]<<endl;
        }
        cout <<endl;
        */
        cout << huda[0] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<list>
using namespace std;
bool b[33000];
int main() {	
	int n, m;
	while (cin >> n >> m&&n != 0) {
		list<int>a;
		list<int>::iterator it;
		list<int>::iterator it2;
		for (int i = 1; i <= n; i++) a.push_back(i);
		for (int z = 0; z < m; z++) {		
			list<int>b;
			int p, s;
			cin >> p >> s;
			for (int i = 0; i < p; i++)it++;
			it2 = it;
			for (int i = 0; i < s; i++) {
				it = it2;
				b.push_back(*it);
				it2 = it;
				it2++;
				a.erase(it);
			}
			b.merge(a);
			a = b;
		}
		it = a.begin();
		cout << (*it) << endl;
	}
}

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

using namespace std;

int main(void)
{
	int n, r;
	while(cin >> n >> r && n!=0 && r != 0)
	{	
		vector<int> A(n);
		for(int i = 0;i < n; i++)
		{
			A[i] = n - i;
		}

		int p, c;

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

			if(c != A.size() && ( (p + c - 1) != n ) )
			{
				rotate(A.begin(), A.begin() + A.size() - p, A.begin() + A.size() - p + c);
			}
			else if( (p + c - 1) == A.size() )
			{
				rotate( A.begin(), A.begin() + A.size() - c, A.end());
			}

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

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

int main(void){
    int n; 
    int r; 
    int p; 
    int c; 

    while(cin >> n >> r){
        if(n==0 && r==0)break;
        int card[n]; 
        int tmp[n]; 

        for (int i=n-1,number=1; i>=0; i--,number++){ 
            card[i] = number;
        }

        for (int i=0;i<n;i++){
            tmp[i] = 0;
        }

        for (int i=0;i<r;i++){
            cin >> p >> c;
            for(int j=0;j<p-1;j++){
                tmp[j] = card[j];
            }
            for(int j=0;j<c;j++){
                card[j] = card[j+p-1];
            }
            for(int j=0;j<p-1;j++){
                card[c+j]=tmp[j];
            }
        }
        cout << card[0] << endl;
    }
    return 0;
}

C++: #include <stdio.h>
int main()
{
  int k[51],i,n,r,y[51],a,b,ka,j;
  while(1){
    scanf("%d %d",&n,&r);
    if(n==0&&r==0)break;
    for(i=0;i<n;i++){
      k[i]=i+1;
      y[i]=i+1;
    }
    for(i=0;i<r;i++){
      scanf("%d %d",&a,&b);
      ka=1;
      for(j=0;j<b;j++){
	y[n-a-b+ka]=k[n-a-b+ka];
	ka++;
      }
      //printf("%d %d %d %d %d",k[0],k[1],k[2],k[3],k[4]);//
      ka=1;
      for(j=0;j<a-1;j++){
	k[n-a-b+ka]=k[n-a+ka];
	ka++;
      }
      ka=1;
      for(j=0;j<b;j++){
	k[n-b-1+ka]=y[n-a-b+ka];
	ka++;
      }
    }
    printf("%d\n",k[n-1]);
  }
  return 0;
}

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

int main() {
        int i, j;
        int n, r;
        while (cin >> n >> r) {
                if (n == 0 && r == 0) break;
                vector<int> a(n);
                vector<bool> ok(n);
                for (i = 0; i < n; i ++) {
                        a[i] = i + 1;
                        ok[i] = true;
                }
                for (i = 0; i < r; i ++) {
                        int p, c;
                        cin >> p >> c;
                        int cnt = 0;
                        int pp = a.size() - 1;
                        while (cnt < p - 1) {
                                if (ok[pp]) cnt ++;
                                pp --;
                        }
                        cnt = 0;
                        vector<int> tmp;
                        vector<bool> tmpok;
                        while (cnt < c) {
                                if (ok[pp]) {
                                        cnt ++;
                                        ok[pp] = false;
                                        tmp.push_back(a[pp]);
                                        tmpok.push_back(true);
                                }
                                pp --;
                        }
                        for (j = tmp.size() - 1; j >= 0; j --) a.push_back(tmp[j]);
                        for (j = tmpok.size() - 1; j >= 0; j --) ok.push_back(tmpok[j]);
                        //cout << "================" << endl;
                        //for (j = 0; j < a.size(); j ++) {
                        //        cout << a[j] << ' ' << endl;
                        //}
                }
                cout << a.back() << endl;
        }
        return 0;
}

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

using namespace std;

int main(){
  int n ,r;
  while (cin >> n >> r){
    if (n == 0 && r == 0){
      return 0;
    }
    stack<int> cards;

    for (int i=0; i<n; ++i){
      cards.push(i+1);
    }
    
    for (int i=0; i<r; ++i){
      int p, c;
      cin >> p >> c;//上からP枚目からC枚とってシャッフル
      int *tmp1 = new int[p-1];
      for (int i=(p-2); 0<=i; --i){
	tmp1[i] = cards.top();
	cards.pop();
      }
      int *tmp2 = new int[c];
      for (int i=(c-1); 0<=i; --i){
	tmp2[i] = cards.top();
	cards.pop();
      }
      for (int i=0; i<(p-1); ++i){
	cards.push(tmp1[i]);
      }
      for (int i=0; i<c; ++i){
	cards.push(tmp2[i]);
      }
      delete[] tmp1;
      delete[] tmp2;      
    }
    cout << cards.top() << endl;
  }
  return 0;
}