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;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  while(true) {
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    vector<int> card;
    REP(i, n) card.push_back(i+1);
    REP(i, r) {
      int p, c;
      cin >> p >> c;
      vector<int> temp;
      REP(i, c) temp.push_back(card[n-c-p+i+1]);
      card.erase(card.begin()+n-c-p+1, card.begin()+n-p+1);
      REP(i, c) card.push_back(temp[i]);
    }

    cout << card[n-1] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)
#define COUNTER int i= 0,j = 0,k = 0,l = 0,m = 0, n= 0;
#define RETURN cout << endl;

using namespace std;

int main (void){
    
    COUNTER
    int number;
    int r;
    
    while(cin >> number >> r ,number+r)
    {
        int p,c;
        
        vector<int>d(51,0);
        for(int i = 0; i<= number;i++){d[i] = number-i;}
        for(int i = 0; i< r;i++)
        {
            cin >> p >> c;
            vector<int>temp(51,0);
            for(int i = p-1; i< p-1+c;i++)
            {
                temp[i] = d[i];
               // cout << temp[i] << endl;
            }
            for(int l = 0; l < c;l++)
            {
                //cout << d[p-1];
                d.erase(d.begin()+p-1);
                
            }
            d.insert(d.begin(),temp.begin()+p-1,temp.begin()+c+p-1);
            /*REP(i,number)
            cout << d[i] << " ";*/
        }
        cout << d[0] << endl;
        
    }

    return 0;
}

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

using namespace std;

int main(){
    while(true){
        int n, r;
        cin >> n >> r;
        if(n==0 && r==0) return 0;
        vector<int> deck(n);

        for(int i=0;i<deck.size();i++){
            deck[i] = deck.size() - i;
        }

        //      for(int k=0;k<n;k++) cerr << deck[k];
//        cerr << endl;

        for(int i=0;i<r;i++){
            int p,c;
            cin >> p >> c;
            vector<int> cdeck = deck;

            for(int j=0;j<c;j++){
                deck[j] = cdeck[p-1+j];
            }

            for(int j=0;j<p-1;j++){
                deck[c+j] = cdeck[j];
            }

            //for(int k=0;k<n;k++) cerr << deck[k];
//            cerr << endl;
        }
        cout << deck[0] << endl;
    }
}

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

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, r;
    while(cin >> n >> r, n or r)
    {
        vector<int> v(n);
        iota(v.begin(), v.end(), 1);
        for(int i = 0; i < r; i++)
        {
            int p, c; cin >> p >> c;
            vector<int> tmp(v.begin() + n - p - c + 1, v.begin() + n - p + 1);
            v.erase(v.begin() + n - p - c + 1, v.begin() + n - p + 1);
            v.insert(v.end(), tmp.begin(), tmp.end());
        }
        cout << v.back() << endl;
    }
    return 0;
}

C++: #include <stdio.h>

void swap(int n, int p, int c, int* card){
  int *temp1 = new int[p-1];
  int *temp2 = new int[c];
  for(int i=0; i<p-1; i++){
    temp1[p-1-1-i] = card[n-1-i];
  }
  for(int i=0; i<c; i++){
    temp2[c-1-i] = card[n-p-i];
  }
  for(int i=0; i<c; i++){
    card[n-1-i] = temp2[c-1-i];
  }
  for(int i=0; i<p-1; i++){
    card[n-1-c-i] = temp1[p-1-1-i];
  }
  delete[] temp1;
  delete[] temp2;
}

int main(void){
  int n, r, p, c;
  int i;
  int card[50];

  while(1){
    for(i=0;i<50;i++){
      card[i]=i+1;
    }
    scanf("%d%d", &n, &r);
    if(n==0 && r==0){
      break;
    }
    for(i=0;i<r;i++){
      scanf("%d%d", &p, &c);
      swap(n, p, c, card);
    }
    printf("%d\n", card[n-1]);
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int n, k, t, m;
	int a[100];
	int b[100];
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
while(true) {

	scanf("%d %d", &n, &m);
	if (n == 0 && m == 0)return 0;
	f(i, n)a[i] = n - i;
		f(i, m) {
			scanf("%d %d", &x, &y);
			f(i, n)b[i] = a[i];
			f(i, y)b[i] = a[i + x - 1];
			f(i, x - 1)b[y + i] = a[i];
			f(i, n)a[i] = b[i];
		}
		printf("%d\n", a[0]);
	}



	return 0;
}