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 <vector>
using namespace std;

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(&yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i];
  }
  cout << endl;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <tuple>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(;;){
    int n,r;
    deque<int> deck;
    cin >> n >> r;
    REP(i,n) deck.push_front(i+1);
    if(!n&&!r) return 0;
    REP(i,r){
      int p,c;
      cin >> p >> c;
      REP(j,c){
	deck.push_front(deck[p+c-2]);
	deck.erase(deck.begin()+p+c-1);
      }
    }
    cout << deck.front() << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int n,r;
  while(cin>>n>>r,n!=0||r!=0){
  int A[n];
  rep(i,n){
    A[i]=n-i;
  }
  rep(i,r){
    int p,c;
    cin>>p>>c;
    vector<long long> v(c);
    for(int j=p-1;j<p+c-1;j++){
      v[j-(p-1)]=A[j];
    }
    for(int j=p-2;j>=0;j--){
      A[j+c]=A[j];
    }
    for(int j=0;j<c;j++){
      A[j]=v[j];
    }
  }
  cout<<A[0]<<endl;
  }
 return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,r,p,c;
	while(1){
		cin>>n>>r;
		if(n==0 && r==0)break;
		int dt[n];
		int alt[n];
		rep(i,n)alt[i]=0;
		for(int i=n;i>0;i--){
			dt[n-i]=i;
			alt[i-1]=0;
		}
		rep(i,n)cout<<dt[i]<<" ";
		cout<<endl;
		rep(j,r){
			cin>>p>>c;
			loop(i,p+c-1,n)alt[i]=dt[i];
			rep(i,p-1)alt[c+i]=dt[i];
			loop(i,p-1,p+c-1)alt[i-p+1]=dt[i];
			rep(i,n)dt[i]=alt[i];
		}
		cout<<dt[0]<<endl;
	}
	return 0;
}

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

int solve(int n,int r){
    vector<int> m;
    for(int i=0;i<n;i++){
        m.push_back(i);
    }
    for(int i=0;i<r;i++){
        int p,c;
        scanf("%d %d",&p,&c);
        rotate(m.begin(),m.begin()+p-1,m.begin()+p+c-1);
    }
    return n-m[0];
}

int main(){
    while(1){
        int n,r;
        scanf("%d %d",&n,&r);
        if(n==0&&r==0) return 0;
        printf("%d\n",solve(n,r));
    }
}

C++: #include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        pair<int, int> n; cin >> n.first >> n.second;
        if(n.first == 0 and n.second == 0) return 0;
        else{
            vector<int> Card(n.first);
            int tmp = n.first;
            for(int i = 0; i < n.first; i++){
                Card[i] = tmp;
                tmp--;
            }
            REP(i, n.second){
                pair<int, int> cut; cin >> cut.first >> cut.second;
                vector<int> New(0);
                for(int i = cut.first - 1; i < cut.first + cut.second - 1; i++) New.push_back(Card[i]);
                REP(i, cut.first - 1) New.push_back(Card[i]);
                FOR(i, cut.first + cut.second - 1, n.first) New.push_back(Card[i]);
                REP(i, n.first) Card[i] = New[i];
            }
            cout << Card[0] << endl;
        }
    }
}

C++: #include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main(void) {
  int n, r;
  int c, p;
  int yama[51];
  queue<int> s;

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

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

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

	  for (int j = 0; j < c; j++) {
		s.push(yama[n - p - j]);
	  }

	  for (int j = n - p + 1; j < n; j++) {
		yama[j - c] = yama[j];
	  }

	  for (int j = 1; j <= c; j++) {
		yama[n - j] = s.front();
		s.pop();
	  }
	}
	cout << yama[n - 1] << endl;
  }
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

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

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	} 

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]-c[i]-1)>=ans){
		}else if(ans>=(n-c[i]+1)){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	printf("%d\n",ans);
	}

	}
	return 0;
}