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<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, r;
	VI ps, cs, cards, temp;
	while(1){
		ps.clear();
		cs.clear();
		cards.clear();
		cin >> n >> r;
		if(n == 0 && r == 0) break;
		rep(i, n){
			cards.pb(i + 1);
		}
		reverse(all(cards));
		rep(i, r){
			int p, c;
			cin >> p >> c;
			ps.pb(p);
			cs.pb(c);
		}
		rep(i, r){
			temp.clear();
			REP(j, ps[i] - 1, ps[i] + cs[i] - 1){
				temp.pb(cards[j]);
			}
			rep(j, ps[i] - 1){
				temp.pb(cards[j]);
			}
			REP(j, ps[i] + cs[i] - 1, cards.size()){
				temp.pb(cards[j]);
			}
			cards.clear();
			cards = temp;
		}
		cout << cards[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <array>

using namespace std;

int main(){
    int A[51];
    int n,m,p,c;
    while(true){
        cin >> n >> m;
        if(n+m == 0)break;
        for(int i = 0;i < n;i++)A[i] = n - i;
        for(int i = 0;i < m;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);
//            for(int k = 0;k < n;k++){
//                cout << A[k] << " ";
//            }
//            cout << endl;
        }
        cout << A[0] << endl;
    }
}

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

#define INF 1000000007LL
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)

int n,r,p[55],c[55];

int main(){
	while(cin>>n>>r && n){
		rep(i,r)cin>>p[i]>>c[i];
		int x=1;
		for(int i=r-1;i>=0;i--){
			if(x<=c[i])x+=p[i]-1;
			else if(x<=c[i]+p[i]-1)x-=c[i];
			cout<<x<<endl;
		}
		cout<<n+1-x<<endl;
	}
}

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

using namespace std;
#define all(a)a.begin(),a.end()
const int INF = 1<<30;
const int mod= int(1e9)+7;

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

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

#define TEST 0 //??\??????????????????(1:??????????????\??? 0:?¨??????\???)
#if TEST
FILE *in = freopen("./Q/A", "r", stdin);
FILE *out = freopen("./A/A", "w", stdout);
#endif

int card[2][50];

int calIndex(int i, int p, int c){
    if(i < c){
        return p+i-1;
    } else if(i < p+c-1){
        return i-c;
    } else {
        return i;
    }
}

void setCard(int n, int turn, int p, int c){
    for(int i = 0; i < n; i++){
        card[turn][i] = card[(turn+1)&1][calIndex(i,p,c)];
    }
}

int main(int argc, const char * argv[]) {
    while(1){
        int n, r; cin >> n >> r;
        if(!n && !r) break;
        
        for(int i = 0; i < n; i++){
            card[1][i] = n-i;
        }
        
        for(int i = 0; i < r; i++){
            int turn = i & 1;
            
            int p, c; cin >> p >> c;
            setCard(n, turn, p, c);
            
        }
        cout << card[(r+1)&1][0] << endl;
        
    }
    
    
#if TEST
    fclose(in);
    fclose(out);
#endif
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
using namespace std;

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read_n(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> void write(const T &t) { cout << t << endl; }
struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

/// template end ///

int main()
{
	while (true)
	{
		READ(int, n, r);
		if (!n && !r) { break; }
		deque<int> deck;
		REP(i, n) deck.push_back(n - i);

		REP(i, r)
		{
			READ(int, p, c); p--;
			vector<int> cut(RANGEOF(deck, p, c));
			deck.erase(RANGEOF(deck, p, c));
			deck.insert(deck.begin(), ALLOF(cut));
		}
		write(deck.at(0));
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r;
  while(cin >> n >> r,n){
    vector<int> a(n);
    for(int i=0; i<n; i++) a[i] = n-i;

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

      vector<int> v1,v2;
      for(int j=0; j<p-1; j++) v1.push_back(a[j]);
      for(int j=0; j<c; j++) v2.push_back(a[j+p-1]);
      for(int j=0; j<c; j++) a[j] = v2[j];
      for(int j=0; j<p-1; j++) a[j+c] = v1[j];
    }
    cout << a[0] << endl;
  }
  return 0;
}

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

int main() {
	int n,r;//1~50
	int p,c;
	int card[50]={};
	int cut[50]={};
	int i,j;
	int finish=0;
	
	scanf("%d%d",&n,&r);
	while(finish==0){
	for(i=0;i<n;i++){
		card[i]=n-i;
//		printf("0\t %d\n",card[i]);
	}
	for(j=0;j<r;j++){
		scanf("%d%d",&p,&c);
		for(i=0;i<c;i++){
			cut[i]=card[p+i-1];
//			printf("1\t %d\n",cut[i]);
		}
		for(i=p-2;i>-1;i--){
			card[i+c]=card[i];
//			printf("2\t %d\n",card[i]);
		}
		for(i=0;i<c;i++){
			card[i]=cut[i];
		}
	}
//	for(i=0;i<n;i++){
//		printf("3\t %d\n",card[i]);
//	}
	printf("%d\n",card[0]);
	scanf("%d%d",&n,&r);
	if((n==0)&&(r==0)){finish=1;}
	}
	return 0;
}

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

int main(){
	while(1){
		int n,r;
		std::cin>>n>>r;
		if(n==0&&r==0)break;
		std::vector<int>v;
		std::vector<int>Av;
		for(int i=n;i>=1;i--)v.push_back(i);
		for(int i=0;i<r;i++){
			int p,c;
			std::cin>>p>>c;
			for(int j=p-1;j<p-1+c;j++)Av.push_back(v[j]);
			//for(int j=0;j<Av.size();j++)std::cout<<Av[j]<<std::endl;
			for(int j=p-1+c;j>=c;j--)v[j]=v[j-c];
			for(int j=0;j<Av.size();j++)v[j]=Av[j];
			Av.clear();
		}
		std::cout<<v[0]<<std::endl;
	}
	return 0;
}