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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m;
struct cards
{
    int from,to;
    cards(int f,int t)
    {
        from=f,to=t;
    }
};
deque<cards> all;
deque<cards> split(int k)
{
    deque<cards> sub;
    for(;;)
    {
        cards t=all.front();
        all.pop_front();
        k -= t.to-t.from+1;
        if(k==0)
        {
            sub.pb(t);
            break;
        }
        if(k<0)
        {
            all.push_front(cards(t.to+k+1,t.to));
            t.to+=k;
            sub.pb(t);
            break;
        }
        sub.pb(t);
    }
    return sub;
}
void shuffle(int x,int y)
{
    deque<cards> a=split(x);
    deque<cards> b=split(y);
    for(int i=0;i<a.size();i++)all.push_front(a[i]);
    for(int i=0;i<b.size();i++)all.push_front(b[i]);
}
int main()
{
    while(1)
    {
        cin >> n >> m;
        if(n==0&&m==0)break;
        all.clear();
        all.pb(cards(1,n));
        for(int i=0;i<m;i++)
        {
            int p,c;
            cin >> p >> c;
            shuffle(p-1,c);
        }
        cout << n-all[0].from+1 << endl;
    }
    return 0;
}

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

int main(){
    int card[51];
    int tmp[50];
    int n,r, from, num;

    while(1){
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        for(int i=1; i<=n; i++){
            card[i]=n-i+1;
        }
        for(int i=0; i<r; i++){
            cin >> from >> num;
            for(int j=0; j<num; j++){
                tmp[j] = card[from+j];
            }
            for(int j=from-1; j>0; j--){
                card[j+num] = card[j];
            }
            for(int j=0; j<num; j++){
                card[j+1] = tmp[j];
            }
        }
        cout << card[1] << endl;
    }
        
    return 0;
}

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

int main(){
  int n=1,r=1,p,c;
  vector<int> deck,temp,ans;

  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=n; i>0; --i)deck.push_back(i); //???????????????
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      copy(deck.begin()+p-1,deck.begin()+p+c-1,back_inserter(temp));
      deck.erase(deck.begin()+p-1,deck.begin()+p+c-1);
      copy(deck.begin(),deck.end(),back_inserter(temp));
      deck=temp;
      temp.clear();
    }
    ans.push_back(deck[0]);
    deck.clear();
  }
  for(auto && x: ans)cout << x << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using Int = int64_t;

int main() {
   for(;;) {
      Int n, r;
      std::cin >> n >> r;
      if( n == 0 and r == 0 ) break;
      std::vector<Int> xs(n);
      for(Int i = 0; i < n; ++i) {
         xs[i] = n - i;
      }
      for(Int i = 0; i < r; ++i) {
         Int p, c;
         std::cin >> p >> c;
         std::vector<Int> ys(n);
         for(Int k = 0; k < c; ++k) {
            ys[k] = xs[k+p-1];
         }
         for(Int k = c; k < c+p-1; ++k) {
            ys[k] = xs[k-c];
         }
         for(Int k = p-1+c; k < n; ++k) {
            ys[k] = xs[k];
         }
         xs = ys;
      }
      std::cout << xs[0] << std::endl;
   }
}

C++: #include<iostream>
#include<fstream>
#include<list>

using namespace std;

int main(){

	ifstream fin("in.txt");

	typedef list<int>::iterator Iterator;

	list <int> stock;
	list<int> tmp;

	int n = 0, r = 0;
	int p = 0, c = 0;
	
	while (true){

		cin >> n >> r;
		if (n == 0 && r == 0)break;

		//?????????
		stock.clear();
		tmp.clear();
		for (int i = 1; i <= n; i++){
			stock.push_back(n - i + 1);
		}

		for (Iterator it = stock.begin(); it != stock.end();){
		//	cout << *it << " ";
			it++;
		}
		//cout << endl;

		//cout << stock.front() << endl;


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

			cin >> p >> c;


			Iterator front = stock.begin();
			for (int i = 0; i < p - 1; i++){
				front++;
			}

			Iterator back = stock.begin();
			for (int i = 0; i < p + c - 1; i++){
				back++;
			}

			tmp.splice(tmp.begin(), stock, front, back);

			stock.splice(stock.begin(), tmp);

			for (Iterator it = stock.begin(); it != stock.end();){
			//	cout << *it << " ";
				it++;
			}
			//cout << endl;
		}

		cout << *stock.begin() << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int n, r, p, c;
int cards[50];
int temp[50];

int main()
{
	while( 1 )
	{
		cin >> n >> r;
		if(n==0 && r==0) break;
		
		for(int i=0; i<n; i++) cards[i] = n-i-1;
		for(int i=0; i<r; i++)
		{
			cin >> p >> c;
			memcpy(&temp[0], &cards[p-1], sizeof(int) * c);
			memcpy(&temp[c], &cards[0], sizeof(int) * (p-1));
			for(int j=0; j<p+c-1; j++) cards[j] = temp[j];
		}
		printf("%d\n", cards[0]+1);
   	}
}

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

using namespace std;

int main(){

	int n,r,c,p,ar[50];
	while(cin>>n>>r){
		if(n==0 && r==0) return 0;
		for(int i=0; i<n; i++) ar[i]=n-i;
		for(int i=0; i<r; i++){
			cin>>p>>c;
			int t1[50],t2[50];
			for(int i=0; i<p-1; i++){
				t1[i] = ar[i];
			}
			for(int i=p-1; i<p+c-1; i++){
				t2[i-p+1] = ar[i];
			}
			for(int i=0; i<c; i++){
				ar[i]=t2[i];
			}
			for(int i=c; i<p+c; i++){
				ar[i]=t1[i-c];
			}
		}
		cout<<ar[0]<<endl;
	}

	return 0;
}

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

struct list{
  int number;
  list *next;
};

void Insertlist(list ** ptr, int newnumber){
  if( *ptr == NULL || (*ptr)->number < newnumber){
    list *newcell;
    newcell = (list *)malloc(sizeof(list));
    newcell->number = newnumber;
    newcell->next = *ptr;
    *ptr = newcell;
  }else{
    Insertlist(&(*ptr)->next, newnumber);
  }
}

int main(){

  int n, r;

  while( cin >> n >> r ){

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

    list *root = NULL;
    for(int i = n ; i > 0 ; i--){
      Insertlist(&root,i);
    }
 
    while( r ){
      int p,c;
      cin >> p >> c;

      list *ptr1 = root, *ptr2 = root,*ptr3,*ptr4;
      
      for(int i = 0 ; i < p-2; i++)
	ptr1 = ptr1->next;
      if(p > 1)
	ptr2 = ptr1->next;
      ptr3 = ptr2;
      for(int i = 0; i < c-1 ; i++)
	ptr3 = ptr3->next;
      ptr4 = ptr3->next;
      
      if(p>1){
	ptr1->next = ptr4;
	ptr3->next = root;
	root = ptr2;
      } 
      r--;
    }
    cout << root->number << endl;
  }
  return 0;
}