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 <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

    int n, r;
    while(cin >> n >> r, n) {
        vector< int > card(n);
        for(int i = 0; i < n; i++)
            card[i] = n - i;
        while(r--) {
            int p, c; cin >> p >> c;
            vector< int > temp(c);
            p--;
            for(int cnt = 0, i = p; i < p + c; i++, cnt++)
                temp[cnt] = card[i];
            for(int i = p - 1; i >= 0; i--)
                card[i + c] = card[i];

            for(int i = 0; i < c; i++) {
                //cout << card[i] << " " << temp[i] << endl;
                card[i] = temp[i];
            }

        }

        cout << card[0] << endl;
    }
}

C++: #include <stdio.h>

int cards[50];
int N,R;

int swap(int p, int c)
{
    int t_cards[50];
    for(int i=0; i < N; i++)
        t_cards[i] = cards[i];
    for(int i=0; i < c; i++)
        cards[i] = cards[p-1+i];
    for(int i=0; i < p-1; i++)
        cards[i+c] = t_cards[i];
    return 0;
}

int main(void)
{
    while(true)
    {
        scanf("%d%d", &N, &R);
        if(N==0 && R==0) break;

        for(int i=0; i < N; i++)
            cards[i] = N-i;

        for(int i=0; i < R; i++)
        {
            int p,c;
            scanf("%d%d", &p, &c);
            swap(p, c);
        }
        printf("%d\n", cards[0]);
    }

    return 0;
}

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

using namespace std;

int main() {
    int n, r;

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

        // init
        vector<int> cards(n);
        for (int i = 0; i < n; i++) cards[i] = n - i;

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

            vector<int> cards_(cards);
            for (int j = 0; j < c; j++) cards[j] = cards_[j + p - 1];
            for (int j = 0; j < p - 1; j++) cards[j + c] = cards_[j];

        }

        cout << cards[0] << endl;
    }
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,R;
    cin >> N >> R;
    while(N){
        vector<int> V(N);
        iota(V.rbegin(), V.rend(), 1);
        for(auto i:V)cout << i << endl;
        rep(i,0,R){
            int p,c;
            cin >> p >> c;
            vector<int> tmp(p + c - 1);
            rep(j,0,c){
                tmp[j] = V[j + p - 1];
            }
            rep(j,c,p+c-1){
                tmp[j] = V[j-c];
            }
            rep(j,0,p+c-1){
                V[j] = tmp[j];
            }
        }
        cout << V[0] << endl;
        cin >> N >> R;
    }
}

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

using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
//const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi st(n);
		REP(i, n)
			st[i] = n-i ;

		REP(i, r) {
			vi sw(n);
			REP(i, n)
				sw[i] = st[i];
			int p, c;
			cin >> p >> c;
			REP(j, c)
				sw[j] = st[p-1  + j];
			REP(j, p-1)
				sw[j + c] = st[j];


			REP(i, n)
				st[i] = sw[i];

		}

		cout << st[0] << endl;
	}

	return 0;
}

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

int main(){
  int n,r, start, end;
  vector<int> ans;
  cin >> n >> r;
  while(n||r){
    vector<int> data(n);
    for(int i = 0; i <n;i++){
      data[i] = n-i;
    }
    for(int j = 0; j < r ; j++){
      cin >> start >> end;
      for(int k = 0; k < end;k++){
        int a = data[start+k-1];
        for(int forth = start-1; forth > k; forth--){
          data[k+forth] = data[k+forth-1];
        }
        data[k] = a;
      }
    }
    ans.push_back(data[0]);
    cin >> n >> r;
  }
  for(int i =0;i<(int)ans.size();i++){
    cout << ans[i] << endl;
  }
}

C++: #include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (int)(a); v < (int)(b); ++v)
#define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define PF push_front
#define ALL(x) (x).begin(), (x).end()
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, r, p, c;
	list< int > l1, l2;
	
	while(cin >> n >> r, n){
		l1.CLR();
		l2.CLR();
		
		REP(i, n){
			l1.PF(i + 1);
		}
		
		REP(i, r){
			cin >> p >> c;
			
			list< int >::iterator bitr = l1.begin(), eitr = l1.begin();
			advance(bitr, p - 1);
			advance(eitr, p + c - 1);
			
			l2.splice(l2.begin(), l1, bitr, eitr);
			
			l1.splice(l1.begin(), l2);
		}
		
		cout << l1.front() << endl;
	}
	
	return 0;
}

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

#define FOR(i,a,n) for(int i = a;i<n;i++)
#define REP(i,n) FOR(i,0,n)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) SET(a,0)
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a<b)?a:b

using namespace std;

int deck[50];
int bucket[50];
int n,r;

void init(){
  REP(i,n) deck[i] = n-i;
}

int solve(){
  int p,c;
  init();
  REP(i,r){
    cin >> p >> c;
    REP(j,c){
      bucket[j] = deck[p+j-1];
    }
    for(int j = p-2;j >= 0;j--){
      deck[j+c] = deck[j];
    }
    REP(j,c){
      deck[j] = bucket[j];
    }
  }
  return deck[0];
}

int main(){
  while(true){
    cin >> n >> r;
    if((n|r) == 0) break;
    cout << solve() << endl;
  }
  
}

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

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[50], tmp[50];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
			tmp[i] = n-1;
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			for(int j=0; j < p+c-1; j++){
				if(j<p-1){
					tmp[j+c] = huda[j];
				}else{
					tmp[j-p+1] = huda[j];
				}
			}
			for(int j=0; j<n; j++){
				huda[j] = tmp[j];	
			}
		}
		cout << huda[0] << "\n";
	}
}