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 <iostream>
using namespace std;
void getcard(int *card, int n);
void shuffle(int *card, int p, int c);
int main(){
  int n,r;
  while (cin>>n>>r,n|r!=0){
    int card[n+1];
    getcard(card,n);
    for (int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      shuffle(card,p,c);
    }
    cout<<card[1]<<endl;
  }
}
void getcard(int *card, int n){
  for (int i=1;i<=n;i++){
    card[i]=n+1-i;
  }
}
void shuffle(int *card, int p, int c){
  int temp[p-1];
  for (int i=0;i<p-1;i++){
    temp[i]=card[i+1];
  }
  for (int i=p;i<p+c;i++){
    card[i-p+1]=card[i];
  }
  for (int i=c+1;i<=c+p-1;i++){
    card[i]=temp[i-c-1];
  }
}

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

int main(){
    while(true){
        int n,r;
        cin >> n >> r;
        if(n==0)break;
        vector<int> card(n);
        for(int i=0;i<n;i++){
            card[i]=i+1;
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin >> p >> c;
            int pos=n-p-c+1;
            queue<int> temp;
            for(int j=0;j<c;j++){
                temp.push(card[pos]);
                card.erase(card.begin()+pos);
            }
            while(!temp.empty()){
                card.push_back(temp.front());
                temp.pop();
            }
        }
        cout << card[n-1] << 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(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<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;
}