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 <bits/stdc++.h>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n, r;
vector<int> p, c;
void ops(vector<int> &card, int p, int c) {
    auto tmp = card;
    p--;
    rep(i, c) {
        card[i] = tmp[i + p];
    }
    rep(i, p) {
        card[i + c] = tmp[i];
    }
}
void solve() {
    vector<int> card(n);
    rep(i, n) card[i] = n - i;
    rep(i, r) {
        ops(card, p[i], c[i]);
        // rep(i, n) cout << card[i] << " ";
        // cout << endl;
    }
    cout << card[0] << endl;
}
int main() {
    while (cin >> n >> r, n) {
        p.resize(r);
        c.resize(r);
        rep(i, r) cin >> p[i] >> c[i];
        solve();
    }

    return 0;
}

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

using namespace std;

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

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

		vector<int> cards(n);

		for(int i = 0; i < n; ++i) {
			cards.at(n - i - 1) = i + 1;
		}

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

			vector<int> temp_p;
			vector<int> temp_c;

			copy_n(cards.begin(), p - 1, std::back_inserter(temp_p));
			copy_n(cards.begin() + p - 1, c, std::back_inserter(temp_c));

			copy(temp_c.begin(), temp_c.end(), cards.begin());
			copy(temp_p.begin(), temp_p.end(), cards.begin() + c);
		}

		std::cout << cards.at(0) << std::endl;
	}

	return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

int main(){
        int n,r,table[50],work[50];
        while(cin>>n>>r&&n,r){
                for(int i=0;i<n;i++)table[i]=n-i;
                int p,c;
                for(int i=0;i<r;i++){
                        cin>>p>>c;
                        for(int k=0;k<c;k++)work[k]=table[p-1+k];
                        for(int k=0;k<p-1;k++)work[c+k]=table[k];
                        for(int k=p+c-1;k<n;k++)work[k]=table[k];
                        for(int k=0;k<n;k++)table[k]=work[k];
                }
                cout<<table[0]<<endl;
        }
        return 0;
}

C++: 
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <iomanip>
#include <functional>
using namespace std;
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(int argc, char* argv[])
{
    int n , r;
    while(cin >> n >> r,n!=0 && r!=0){
        int p,c;
        int i=0,j=0;
        int temp[50];
        int huda[50];
        for(i=0;i<n;i++){
            huda[i] = i+1;
        }
        while(r){
            cin >> p >>c;
            for(i = 0;i < c;i++){
                
                temp[i] = huda[((n-1)-(p-2))-(c-i)];
//                cout << temp[i] << endl;
            }
            
            for (j=p-1; j>0;j-- ) {
                huda[(n-j)-c] = huda[n-j];
            }
//            for(i=0;i<10;i++)cout <<huda[i] <<" ";
//            cout<<endl;
            for(i=0;i<c;i++){
                huda[n-(c-i)] = temp[i];
            }
//            for(i=0;i<10;i++)cout <<huda[i] <<" ";
            r--;
        }
            cout << huda[n-1] << endl;
    }
    return 0;
}

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

int solve(int n,int r){
  vector<int> l;
  for(int i=0;i<n;i++){
    l.push_back(i+1);
  }
  l = vector<int>(l.rbegin(),l.rend());
  for(int i=0;i<r;i++){
    int p,c;
    cin>>p>>c;
    vector<int> l1,l2;
    for(int j=0;j<l.size();j++){
      if(j<p-1){
        l1.push_back(l[j]);
      }else if(j<p+c-1){
        l2.push_back(l[j]);
      }else{
        l1.push_back(l[j]);
      }
    }
    for(int j=0;j<l1.size();j++){
      l2.push_back(l1[j]);
    }
    l = l2;
    //for(auto i:l)cout<<i<<" ";cout<<endl;
  }
  return l[0];
}


int main(){
  int n,r;
  while(cin>>n>>r,n!=0&&r!=0){
    cout<<solve(n,r)<<endl;
  }

}

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

bool solve(){
    int n, r;
    cin >> n >> r;
    if(n == 0) return false;
    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;
        p--;
        vector<int> tmp(c);
        for(int j=0;j<c;j++){
            tmp[j] = a[p+j];
        }
        a.erase(a.begin()+p, a.begin()+p+c);
        a.insert(a.begin(), tmp.begin(), tmp.end());
    }
    cout << a.front() << endl;
    return true;
}

int main(){
    while(solve());
    return 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){
    //?±±??????????????????                                                            
    yama.clear();
    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()-1; i++){
    cout << v[i] << endl;
  }
  cout << v[v.size()-1];
  cout << endl;
}

void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);
    for(int j = 0; j < yama.size(); j++){
      cout << yama[j] << " ";
    }
    cout << endl;

  }
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <functional>
using namespace std;
typedef pair<int,int> mypair;

int main(void){
int n,r;
while(1)
{
cin>>n>>r;
if(n==0)break;
vector<mypair> huda(n);
mypair temp;
for(int i=0;i<n;i++){
	temp.first=n-i;
temp.second=n-i;
huda[i]=temp;
}


int p,c;
for(int i=0;i<r;i++){
	cin>>p>>c;
	for(int j=0;j<p-1;j++)
	huda[c+j].first=huda[j].second;
	for(int j=0;j<c;j++)
	huda[j].first=huda[p-1+j].second;
	for(int j=0;j<n;j++){
		huda[j].second=huda[j].first;
	}
	
}
//for(int i=0;i<n;i++)
//cout<<huda[i].first<<' '<<huda[i].second<<endl;
cout<<huda[0].second<<endl;
}
return 0;
}