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<math.h>
#include<string>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define INF 1145141919810893931
using namespace std;

void func(vector<ll> &a,ll p,ll r) {
	vector<ll> temp_p(p-1);
	rep(i, p - 1) temp_p[i] = a[i];
	vector<ll> temp_r(r);
	rep(i, r) temp_r[i] = a[i + p - 1];
	rep(i, r) a[i] = temp_r[i];
	rep(i, p - 1) a[i + r] = temp_p[i];
}

int main() {
	ll n, r; cin >> n >> r;
	vector<ll> a;
	while (n && r) {
		a.resize(n);
		rep(i, n) a[i] = n - i;
		rep(i, r) {
			ll p, c; cin >> p >> c;
			func(a,p,c);
		}cout << a[0] << endl;
		cin >> n >> r;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r,p1,c;
int huda[51],huda2[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>p1>>c;
                        p1--;
                        for(int j=0; j<n; j++) {
                                huda[i]=n-i;
                                huda2[i]=huda[i];
                        }
                        for(int j=0; j<c; j++) {
                                huda2[i]=huda2[i+p1];
                        }
                        for(int j=0; j<p1; j++) {
                                huda2[j+c]=huda[j];
                        }
                        for(int i=0; i<n; i++) {
                                huda[i]=huda2[i];
                        }
                }
                cout<<huda[0]<<endl;
        }
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
	while(1){
		int i,j=0,k,n,r,a[51],b[51],p,c;
		for(i=0;i<51;i++){
			a[i]=i;
			b[i]=i;
		}
		cin>>n>>r;
		if(n==0&&r==0)break;
		//a[0]はつかわない
		for(i=0;i<r;i++){
			cin>>p>>c;
			for(j=p;j<p+c;j++){
				a[j-p+1]=b[j];
			}
			for(j=1;j<p;j++){
				a[c+j]=b[j];
			}
			for(j=0;j<=n;j++){
				b[j]=a[j];
			}
		}
		cout<<n+1-a[1]<<endl;
	}
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,r,p,c,a[100],b[100];
  while(cin>>n>>r){
    if(n==0 && r==0)break;
    for(int i=0;i<n;i++)
      a[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>p>>c;
      for(int i=0;i<n;i++)
	b[i]=a[i];
      for(int i=0;i<c;i++)
	a[i]=b[p-1+i];
      for(int i=0;i<p-1;i++)
	a[c+i]=b[i];
    }
    cout<<a[0]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int n, r, p, c;
    while (true) {
        cin >> n >> r;
        if (n == 0 && r == 0){
            break;
        }
        int before[n];
        
        int after[n];
        for (int i = 1; i <= n; i++) {
            before[n-i] = i;
        }
        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            for (int j = p-1; j < p+c-1; j++) {
                after[j-(p-1)] = before[j];
            }

            
            for (int j = 0; j < p-1; j++) {
                after[c+j] = before[j];
            }
            for (int j = p+c-1; j<n; j++) {
                after[j] = before[j];
            }
            
            for (int j = 0; j < n; j++) {
                before[j] = after[j];
            }
        }
        cout << after[0] << endl;

        
    }
    
    return 0;
}

C++: 5 2
3 1
3 1
10 3
1 10
10 1
8 3
0 0

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


void shuffle(int a, int b, int *ans)
{
    int t[a];
    a--;
    for (int i = 0; i < a; i++) {
        t[i] = ans[i];
    }
    for (int i = a; i < a + b; i++) {
        ans[i - b] = t[i - b];
    }
    for (int i = b; i < a + b; i++) {
        ans[i] = t[i - b];
    }
}
int main()
{
    int n,r;
    while (cin >> n >> r, n) {
        int ans[n];
        for (int i = 0; i < n; i++) {
            ans[i] = n - i;
        }
        for (int i = 0; i < r; i++) {
            int b, e;
            cin >> b >> e;
            shuffle(b, e, ans);
        }
        cout << ans[0] << endl;

    }

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
    int n, r, p[64], c[64];
    while (scanf("%d%d", &n, &r), n | r)
    {
	for (int i = 0; i < r; ++i)
	    scanf("%d%d", p + i, c + i);

	int pos = 0;
	for (int i = r - 1; i >= 0; --i)
	{
	    if (pos < c[i])
		pos += p[i] - 1;
	    else if (pos < c[i] + p[i])
		pos -= c[i];
	}
	printf("%d\n", n - pos);
    }
}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n, r;
	while(cin >> n >> r, n+r){
		int card[n];
		rep(i, n) card[i] = n-i;
		int p, c;
		for(int i=0; i< r; i++){
			cin >> p >> c;

			int a[55], b[55];
			rep(i, p) a[i] = card[i];
			rep(i, c) b[i] = card[p+i-1];
			rep(i, c) card[i] = b[i];
			rep(i, p) card[i+c] = a[i];
		}
		cout << card[0] << endl;
	}
}