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 <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
	int n, r, p, c;
	while (cin >> n >> r&&n&&r) {
		vector<int> vec;
		for (int i = n; i >= 1; i--) {
			vec.emplace_back(i);
		}
		for (int i = 0; i < r; i++) {
			cin >> p >> c;
			for (int j = 0; j < c; j++) {
				vec.insert(vec.begin(),(vec[p + c - 2]));
				vec.pop_back();
			}
		}
		cout << vec[0] << endl;
	}
}

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

int main()
{
    int n, r = 0;
    int p, c = 0;
    while (std::cin >> n >> r && n > 0) {
        std::vector<int> v(n);
        for (int i = 0; i < n; i++) {
            v.at(n - i - 1) = i + 1;
        }
        for (int i = 0; i < r; i++) {
            std::cin >> p >> c;
            std::rotate(v.begin(), v.begin() + p - 1, v.begin() + p + c - 1);
        }
        std::cout << v.at(0) << '\n';
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


int main(){

	int n, r;

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

		int a[n];
		int temp[n];
		int count = n-1;
		for(int i=1 ; i<=n ; i++){
			a[count] = i;
			count--;
		}

		int p, c;
		for(int i=0 ; i<r ; i++){
			cin >> p >> c;
			for(int j=0 ; j<c ; j++){
				temp[j] = a[p-1+j];
			}
			for(int j=0 ; j<p-1 ; j++){
				temp[c+j] = a[j];
			}
			for(int j=c+p-1 ; j<n ; j++){
				temp[j] = a[j];
			}

			for(int j=0 ; j<n ; j++){
				a[j] = temp[j];
			}
		}
		cout << a[0] << endl;

	}

	return 0;
}

C++: // Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

queue <int> deck,temp,tempp;

void shuffle(int x,int c){
    while(x--){
        temp.pp(deck.front());
        deck.pop();
    }
    while(c--){
        tempp.pp(deck.front());
        deck.pop();
    }
    while(temp.size()){
        tempp.pp(temp.front());
        temp.pop();
    }
    while(deck.size()){
        tempp.pp(deck.front());
        deck.pop();
    }
    while(tempp.size()){
        deck.pp(tempp.front());
        tempp.pop();
    }
}

void init(int n){
    while(deck.size()) deck.pop();
    
    for(int i = n ; i >= 1 ; i--) deck.pp(i);
}
main(){
    int n,r;
    int a,b;
    
    while(cin >> n >> r){
        if(n == 0) break;
    
        init(n);
        
        while(r--){
            cin >> a >> b;
            shuffle(a-1,b);
        }
        
        cout << deck.front() << endl;
    }
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}

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

vector<int> v;

int main(){
while(1){//start	
	int n, r;
	cin >> n >> r;
	if(n == 0 and r == 0) break;
	
	for(int i = 1; i <= n; i++) v.push_back(i);
	reverse(v.begin(), v.end());

	for(int i = 0; i < r; i++){
		stack<int> st;
		int p, c;
		cin >> p >> c;
		for(int j = 0; j < c; j++){
			st.push(v[p + j - 1]);
			//cout << "que = " << v[p + j - 1] << endl;
		}
		v.erase(v.begin() + p - 1, v.begin() + p + c - 1);
		//for(int k = 0; k < (int)v.size(); k++) cout << v[k] << endl;
		

		reverse(v.begin(), v.end());
		while(st.size()){
			int tmp = st.top();
			//cout << "tmp = " << tmp;
			st.pop();
			v.push_back(tmp);
		}
		reverse(v.begin(), v.end());

		//debug
		//cout << endl;
		//for(int k = 0; k < (int)v.size(); k++) cout << v[k] << endl;
		//cout << endl;
	}

	cout << v[0] << endl;
	v.clear();
}//end
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  int n,r;
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    int d[51];
    //?????????
    for(int i=0;i<n;i++){
      d[i]=n-i;
    }

    if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
    if(debug)cout<<endl;
      
    for(int i=0;i<r;i++){
      int p,c,tmp[51];
      cin>>p>>c;
      
      for(int j=0;j<c;j++)tmp[j]=d[j+p-1];

      for(int j=p-2;j>=0;j--)d[j+c]=d[j];

      for(int j=0;j<c;j++)d[j]=tmp[j];

      
      if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
      if(debug)cout<<endl;
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


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

		vector<int> s(n);
		std::iota(s.begin(), s.end(), 1);
		reverse(s.begin(), s.end());

		rep(i, r) {
			int p, c;
			cin >> p >> c;
			int toU[100] = { 0 }, toD[100] = { 0 };
			rep(i, c) {
				toU[i] = s[p - 1 + i];
			}
			rep(i, p - 1) {
				toD[i] = s[i];
			}
			rep(i, c) {
				s[i] = toU[i];
			}
			rep(i, p - 1) {
				s[i + c] = toD[i];
			}
		}
	
		cout << s[0] << endl;
	}
	cin >> qqq;
}

C++: #include <iostream>
using namespace std;
int card[50];
int buffer[50];
int 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(int j=0;j<p-1;j++)
				buffer[j]=card[j];
			for(int j=0;j<c;j++)
				card[j]=card[j+p-1];
			for(int j=0;j<p-1;j++)
				card[j+c]=buffer[j];
		}
		cout<<card[0]<<endl;
	}
	return 0;
}