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>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
 
int main() {
    int n, r;
    while(cin >> n >> r, n) {
        vector<int> v(n);
        for(int i=0; i<n; ++i) {
            v[i] = n-i;
        }
         
        for(int i=0; i<r; ++i) {
            vector<int> tmp;
            int p, c;
            cin >> p >> c;
            tmp.insert(tmp.begin(), v.begin()+p-1, v.begin()+p+c-1);
            v.erase(v.begin()+p-1, v.begin()+p+c-1);
            v.insert(v.begin(), tmp.begin(), tmp.end());
        }
        cout << v[0] << endl;
    }
}

C++: #include <iostream>

using namespace std;

#define NMAX 50

int main(){

	int n,r;
	int p,c;
	int tmp;
	int deck[NMAX];

	while(1){

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

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

		while(r--){
			cin>>p>>c;
			for(int k=c-1;k>=0;k--){
				tmp=deck[p-1+c-1];
				for(int i=p-1+c-1;i>0;i--){
					deck[i]=deck[i-1];
				}
				deck[0]=tmp;
			}
		}

		cout<<deck[0]<<endl;

	}

	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	} 

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]-c[i]+1)>=ans){
		}else if(ans>=(n-c[i]+1)){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	printf("%d\n",ans);
	}

	}
	return 0;
}

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

int main() {
    int N, R;
    while (cin >> N >> R, N || R) {
        vector<int> v(N);
        for (int i = 0; i < N; i++) {
            v[i] = i+1;
        }

        while (R--) {
            int p, c;
            cin >> p >> c;
            auto w = v;
            for (int i = 0; i < p-1; i++) {
                w[N - p - c + i + 1] = v[N - p + i + 1];
            }

            for (int i = 0; i < c; i++) {
                w[N - c + i] = v[N - p - c + i + 1];
            }

            v = w;
        }

        for (auto i : v) cout << i << " ";
        cout << endl;

        cout << v[N-1] << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int n, r;
VI ps, cs;
VI cards;

int main(void) {
	while (1) {
		cards.clear();
		ps.clear();
		cs.clear();
		cin >> n >> r;
		if (n ==  0 && r == 0) break;
		rep (i, n) {
			cards.PB(n - i);
		}
		rep (i, r) {
			int p, c;
			cin >> p >> c;
			ps.PB(p);
			cs.PB(c);
		}
		rep (i, r) {
			VI temp;
			REP (j, ps[i] - 1, ps[i] + cs[i] - 1) {
				temp.PB(cards[j]);
			}
			rep (j, ps[i] - 1) {
				temp.PB(cards[j]);
			}
			REP (j, ps[i] + cs[i] - 1, cards.size()) {
				temp.PB(cards[j]);
			}
			cards = temp;
		}
		cout << cards[0] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

void calc(int n,int r){
  stack<int> card;

  for(int i=0;i<n;i++){
    card.push(i+1);
  }

  for(int i=0;i<r;i++){
    int p,c;
    stack<int> s1,s2;

    scanf("%d%d",&p,&c);

    for(int i=0;i<p-1;i++){
      s1.push(card.top());
      card.pop();
    }

    for(int i=0;i<c;i++){
      s2.push(card.top());
      card.pop();
    }

    for(int i=0;i<p-1;i++){
      card.push(s1.top());
      s1.pop();
    }

    for(int i=0;i<c;i++){
      card.push(s2.top());
      s2.pop();
    }

    
    
  }
  
  printf("%d\n",card.top());

}

int main(){
  int n,r;

  while(1){
    scanf("%d%d",&n,&r);
    if(n==0) break;
    calc(n,r);
  }
  
  return 0;
}

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

using namespace std;

int32_t main()
{
  while(true){
    uint32_t n, r;
    cin >> n >> r;
    if(n == 0) break;

    vector<uint32_t> cards(51, 0);
    for(int32_t i = n-1, j = 1;  i >= 0; i--, j++){
      cards[i] = j;
    }

    for(uint32_t i = 0; i < r; i ++){
      uint32_t p, c;
      cin >> p >> c;
      vector<uint32_t> cs;
      for(uint32_t i = p - 1; i < p - 1 + c; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = 0; i < p - 1; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = p - 1 + c; i < n; i++){
        cs.push_back(cards[i]);
      }

      for(uint32_t i= 0; i < n; i++){
        cout << cs[i] << " ";
        cards[i] = cs[i];
      }
      cout << endl;
    }

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

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
using namespace std;


int main()
{
	int n, r, p, c, A[51];
	while (true) {
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		else {
			for (int i = 0; i < n; i++)A[i] = n - i;
			for (int i = 0; i < r; i++) {
				cin >> p >> c;
				rotate(A, A + p - 1, A + p + c - 1);
			}
			cout << A[0] << endl;
			for (int i = 0; i < n; i++)A[i] = 0;
		}
	}
	return 0;
}

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

int main(void)
{
    while(true)
    {
        int n, r; cin >> n >> r;
        if(n == 0 && r == 0) break;

        vector<int> array(n, 0);
        vector<int> copy(n, 0);
        for(int i = 0; i < n; i++){
            array[i] = i+1;
        }
        for(int i = 0; i < r; i++){
            int p, c;
            cin >> p >> c;
            
            for(int j = n - p; j > n - p - c; j--){
                copy[j + p - 1] = array[j];
            }
            for(int j = n - p + 1; j < n; j++){
                array[j - c] = array[j];
            }
            for(int j = n - 1; j > n - 1 - c; j--){
                array[j] = copy[j];
            }
            
        }

        cout << array[n-1] << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;

int main() {
	cin.sync_with_stdio(false);
	int n,r;
	vector<int>ans;
	while (1) {
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		vector<int>b(n), a(n);
		int p, c;
		rep(i, n)b[i] = n-i;
		rep(i, r) {
			cin >> p >> c;
			rep(j, c)a[j] = b[p - 1 + j];
			rep(j, p-1)a[c + j] = b[j];
			reps(j, p + c - 1, n)a[j] = b[j];
			rep(j, n)b[j] = a[j];			
		}
		ans.push_back(a[0]);

	}
	for (auto x : ans)cout << x << endl;
	return 0;
}

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

void show(int* x, int n);

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