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 "bits/stdc++.h"
using namespace std;

//#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

signed main() {
	int n;
	while (cin >> n && n) {
		int r; cin >> r;
		V cards(n);
		rep(i, n) cards[i] = n - i;
		rep(_, r) {
			int p, c; cin >> p >> c;
			p--;
			rep(i, c) {
				for (int idx = p + i; idx - 1 >= i; idx--) {
					swap(cards[idx - 1], cards[idx]);
				}
			}
		}
		cout << cards[0] << endl;
	}
}

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

using namespace std;

void shuffle(int *cards,int p, int c){
	int *mt1 = new int[p-1];
	for(int i=0;i<p-1;i++){
		mt1[i] = cards[i];
	}	
	int *mt2 = new int[c];
	for(int i=0;i<c;i++){
		mt2[i] = cards[p-1+i];
	}
	for(int i=0;i<c;i++){
		cards[i] = mt2[i];
	}
	for(int i=0;i<p-1;i++){
		cards[c+i] = mt1[i];
	}
	delete[] mt1;
	delete[] mt2;
}

int main(){
	int n,r;//カードの枚数,シャッフルの回数
	while(true){
		cin >> n >> r;
		if(n==0 && r==0){
			break;
		}
		int *cards = new int[n];
		for(int i=0;i<n;i++){
			cards[i] = n-i;
		}
		for(int i=0;i<r;i++){
			int p,c;//上からpの場所からc個
			cin >> p >> c;
			shuffle(cards,p,c);
		}
		int result = cards[0];
		cout << result << endl;
		delete[] cards;
	}
	
	return 0;
}

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

#define rep(i,n)  for(int i=0; i<n; i++)

int main(){
  int n, r;
  while(true){
    cin>>n>>r;
    if(n==0 && r==0)break;
    int ans=n;
    stack<pair<int, int> > st;
    rep(i,r){
      int p, c;
      cin>>p>>c;
      st.push(pair<int, int>(p, c));
    }
    while(!st.empty()){
      pair<int, int> tmp=st.top(); st.pop();
      if(ans>(n-tmp.second)){ans-=(tmp.first-1);}//オレンジ
      else if(ans>(n-tmp.first-tmp.second+1)){ans+=tmp.second;}//ブルー
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
  
  int n, r, p, c;
  int card[60], tmp[60];

  while(cin>>n>>r, n){
    for(int i=0;i<n;i++) card[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>p>>c;
      for(int j=0;j<c;j++) tmp[j]=card[p-1+j];
      for(int j=0;j<p;j++) card[p-1+c-j-1]=card[p-1-j-1];
      for(int j=0;j<c;j++) card[j]=tmp[j];
    }
    cout<<card[0]<<endl;
  }
  
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n, r; cin >> n >> r;
		if (n == 0) break;
		string s(n, ' ');
		for (int i = 0; i < n; i++) s[i] = n - i;
		while (r--) {
			int p, c; cin >> p >> c;
			string _s = s.substr(p - 1, c) + s.substr(0, p - 1) + s.substr(p + c - 1);
			s = _s;
		}
		cout << (int)s[0] << endl;
	}
}

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

using namespace std;

int main(){
    tuple<int,int,int> a;
}

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

int main() {
int N,R,p,c;
while (cin>>N>>R&&N) { 
	int A[100]={};
	for(int i=0;i<N;i++){
		A[i]=i+1;
	}
	reverse(A,A+N)
	for (int i=0; i<R; ++i) {
	cin >> p >> c ;
	rotate(A,A+p,A+p+c);

 }
 cout << A[0] << endl;
 }
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;


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


	return 0;
}

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

int main(){
    int n,r;
    for(;;){
        scanf("%d%d",&n,&r);
        if(n==0 && r==0) break;
        int p,c;
        vector<int> ca(n);
        for(int i=0;i<n;i++){
            ca[i]=n-i;
        }
        for(int i=0;i<r;i++){
            scanf("%d%d",&p,&c);
            rotate(begin(ca),begin(ca)+p-1,begin(ca)+p-1+c);
        }
        printf("%d\n",ca[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 d[55];

void init(int n){
  for(int i=0;i<51;i++){
    d[i]=n-i;
  }
}

int main(){
  int n,r;

  while(true){
    cin>>n>>r;
    if(n==0&&r==0)break;
    init(n);
    for(int i=0;i<r;i++){    
      int p,c;
      cin>>p>>c;
  
      int tmp[55];
      for(int j=0;j<c;j++){
        tmp[j]=d[p+j-1];
      }
      //if(debug)for(int j=0;j<c;j++)cout<<tmp[j]<<" ";
      for(int j=p-1;j>0;j--){
	d[j+c]=d[j];
      }
      for(int j=0;j<c;j++){
	d[j]=tmp[j];
      }
      if(debug)for(int j=0;j<n;j++)cout<<d[j]<<" ";
      if(debug)cout<<endl;
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

/*

1 2 3 4 5 
3 1 2 4 5


 */

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,r;
	while(cin>>n>>r,r){
		int cards[60],i;
		for(i=0;i<60;i++)cards[i]=i;
		for(i=0;i<r;i++){
			int a,b;
			cin>>a>>b;
			a--;
			int j;
			int c[60];
			for(j=0;j<60;j++){
				if(j<b){
					c[j]=cards[a+j];
				}else if(j<a+b){
					c[j]=cards[j-b];
				}else{
					c[j]=cards[j];
				}
			}
			for(j=0;j<60;j++){
				cards[j]=c[j];
//cout<<cards[j]<<endl;
			}
//cout<<endl;
		}
		cout<<n-cards[0]<<endl;
	}
	return 0;
}