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 <algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main() {
    int n, r;
    while(cin >> n >> r, n) {
        vector<int> v(n);
        for(int i=0; i<n; ++i) {
            v[i] = n-i;
        }
        
        for(int i=0; i<r; ++i) {
            vector<int> tmp;
            int p, c;
            cin >> p >> c;
            tmp.insert(tmp.begin(), v.begin()+p-1, v.begin()+p+c-1);
            v.erase(v.begin()+p-1, v.begin()+p+c-1);
            v.insert(v.begin(), tmp.begin(), tmp.end());
        }
        cout << v[0] << endl;
    }
}

C++: #pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
//typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    while(true){
        int N,R;
        cin>>N;
        if(N==0) return 0;
        cin>>R;
        vector<int> V[51];
        for(int i=N;i>=1;i--) V[0].push_back(i);

        for(int j=0;j<R;j++){
            int p,c;
            cin>>p>>c;
            for(int i=0;i<c;i++){
                int x=i+p-1;
                V[j+1].push_back(V[j][x]);
            }
            for(int i=0;i<N;i++){
                if(i>=p-1 && c+p-2>=i) continue;
                V[j+1].push_back(V[j][i]);
            }
        }
        cout<<V[R][0]<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int card[50];
int buffer[50];
void main()
{
	int n,r;
	while(cin>>n>>r,n!=0){
		for(int i=0;i<n;i++)card[i]=i+1;
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(j=0;j<p-1;j++)
				buffer[j]=card[j];
			for(j=0;j<c;j++)
				card[j]=card[j+p-1];
			for(j=0;j<p-1;j++)
				card[j+c-1]=buffer[j];
		}
		cout<<card[0]<<endl;
	}
}

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

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

using namespace std;

int main() {
	int r,c;
	while (cin >> r >> c) {
		if (r == 0 && c == 0) {
			break;
		}

		if (r % 2 == 1 && c % 2 == 1) {
			cout << "no" << endl;
		}
		else {
			cout << "yes" << endl;
		}
	}
	return 0;
}

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 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 cards;
	vector<PII> cuts;
	while(1){
		cards.clear();
		cuts.clear();
		cin >> n >> r;
		if(n == 0 && r == 0) break;
		rep(i,r){
			int p, c;
			cin >> p >> c;
			cuts.pb(mp(p, c));
		}
		rep(i, n){
			cards.pb(n - i);
		}
		rep(i, r){
			VI cs(n);
			int p = cuts[i].first;
			int c = cuts[i].second;
			int now = 0;
			REP(j, p - 1, p + c - 1){
				cs[now++] = cards[j];
			}
			rep(j, p){
				cs[now++] = cards[j];
			}
			REP(j, p + c, cards.size()){
				cs[now++] = cards[j];
			}
			cards = cs;
		}
		cout << cards[0] << endl;
	}
	return 0;
}

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

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

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

using namespace std;

list <int> hsf(list <int> li, int c, int p) {
  list <int> :: iterator i1, i2;
  list <int> :: iterator ii;

  if (p == 1) return li;

  i1 = i2 = li.begin();

  advance(i1, p-1);
  advance(i2, c + (p-1));

  li.splice(li.begin(), li, i1, i2);

  return li;

}


int main(void) {

  for (;;) {
    list <int> c1, c2;
    vector <int> c, p;
    int i, j;
    int n, r;

    cin >> n;
    cin >> r;
    if (n == 0 || r == 0) {
      break;
    }
    
    for (i = 0; i < r; i++) {
      int x, y;
      cin >> x;
      cin >> y;
      c.push_back(y);
      p.push_back(x);
    }

    for (j = 0; j < n; j++) {
      c1.push_front(j+1);
    }
  
    for (i = 0; i < r; i++) {
      c2 = hsf(c1, c[i], p[i]);
      c1 = c2;
    }

    list <int> :: iterator ii;

    ii = c1.begin();
    cout << *ii;
    cout << endl;
  }

  
  return 0;

}