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;
int main() {
    int n, m;
    while (true) {
        cin >> n >> m;
        if (!n && !m) break;
        int p, c;
        vector<int> a(n);
        vector<int> b;
        for (int i = 0; i < n; ++i) {
            a[i] = n-i;
        }
        for (int i = 0; i < m; ++i) {
            cin >> p >> c;
            for (int j = p-1; j < p+c-1; ++j) {
                b.push_back(a[j]);
            }
            for (int j = 0; j < p; ++j) {
                b.push_back(a[j]);
            }
            for (int j = p+c; j < n; ++j) {
                b.push_back(a[j]);
            }
            a = b;
            b.clear();
        }
        cout << a[0] << endl;
    }
}

C++: #include <iostream>

using namespace std;

int cut(int n, int r, int p, int c, int s[60]){
	int temp[60] = {0};

	for(int i = 0;i < r;i++){
		for(int j = 0;j <= n;j++){
			temp[j] = s[j];
		}
		for(int j = 0;j < p;j++){
			s[n - p - c + j + 2] = temp[n - p + j + 2];
		}
		for(int j = 0;j < c;j++){
			s[n - c + 1 + j] = temp[n - p - c + j + 2];
		}
	}

	return s[n];
}

int main(){
	int n, r, p, c, s[60];
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0) break;

		for(int i = 0;i <= n;i++){
			s[i] = i;
		}
		cin >> p >> c;

		if(n + 1 < p + c) continue;

		int ans = cut(n, r, p, c, s);

		cout << ans << endl;
	}

	return 0;
}

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

void shuffleCards( int* a, int n, int p, int c )
{
    int copy1[p], copy2[c];
    for( int i = 1; i < p; i++ )
        copy1[i] = a[n+1-i];

    for( int i = p; i < p + c; i++ )
        copy2[i-p] = a[n+1-i];

    for( int i = 1; i <= c; i++ )
        a[n+1-i] = copy2[i-1];

    for( int i = 1; i < p; i++ )
        a[n+1-c-i] = copy1[i];
    
}

int main()
{
    int n, r, a[51], p, c;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        for( int i = 1; i <= 50; i++ )
            a[i] = i;

        cin >> r;

        for( int i = 0; i < r; i++ )
        {
            cin >> p >> c;
            shuffleCards( a, n, p, c );
        }
        cout << a[n] << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int n, r;
  while(1) {
    cin >> n >> r;
    if(n==0 && r==0) break;
    int num[n+1];
    FOR(i,0,n+1) num[i] = i;
    while(r--) {
      int p, c;
      scanf("%d %d\n", &p, &c);
      int tmp[c+p];
      FOR(i,0,c) {
        tmp[i] = num[n-p+1-i];
      }
      FOR(i,c,c+p) {
        tmp[i] = num[n-i+c];
      }
      FOR(i,0,c+p) num[n-i] = tmp[i];
    }
    printf("%d\n", num[n]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<ll,ll> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{   
    int n,r;
    while(cin>>n>>r,n!=0)
    {
        stack<int>l;stack<int>cc;stack<int>pp;
        REP(i,n)l.push(i+1);
        REP(i,r)
        {
            int p,c;
            cin>>p>>c;
            REP(j,p-1)
            {
                pp.push(l.top());l.pop();
            }
            REP(j,c)
            {
                cc.push(l.top());l.pop();
            }
            REP(j,p-1)
            {
                l.push(pp.top());pp.pop();
            }
            REP(j,c)
            {
                l.push(cc.top());cc.pop();
            }
        }
        cout<<l.top()<<endl;
    }
}

C++: #include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define fori(i,k,n) for(int i=k;i<n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };



int main()
{
	int r, l;
	cin >> l >> r;
	while (1)
	{
		if (l == r&&r == 0)break;
		vector<int> h;
		for (int i = l; i >=1; i--)h.push_back(i);
		for (int i = 0; i < r; i++)
		{
			vector<int> now;
			int p, c;
			cin >> p >> c;
			for (int k = p - 1; k < p - 1 + c; k++)
			{
				now.push_back(h[k]);
			}
			for (int k = 0; k < p - 1; k++)
			{
				now.push_back(h[k]);
			}
			for (int k = p - 1 + c; k < h.size(); k++)
			{
				now.push_back(h[k]);
			}
			for (int k = 0; k < h.size(); k++)
			{
				h[k] = now[k];
			}
		}
		cout << h[0] << endl;
		cin >> l >> r;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int data[50], n, r, p, c, tmp[50], next[50];

main(){
  while(cin >> n >> r && (n|r)){
    for(int i=0;i<n;i++) data[i] = n-i;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=0;j<p-1;j++) tmp[j] = data[j];
      for(int j=0;j<c;j++) next[j] = data[p-1+j];
      for(int j=0;j<p-1;j++) next[c+j] = tmp[j];
      for(int j=p+c-1;j<n;j++) next[j] = data[j];
      for(int j=0;j<n;j++) data[j] = next[j];
    }
    cout << data[0] << endl;
  }
}

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

using namespace std;


int main()
{
	int n,r,p,c;

	while(cin >> n >> r){
		if((n==0)&&(r==0)){return 0;}
		vector<int> card;
		for(int i=0; i<n; i++){
			card.push_back( n-i );
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			rotate(card.begin(),card.begin()+p-1, card.begin()+p-1+c);
		}
		cout << card[0] << endl;
	}
}

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

int main()
{
  int n, r;
  while(cin >> n >> r and (n > 0 or r > 0)){
    vector<int> card(n);
    for (int i = 0; i < n; i++) {
      card[i] = n - i;
    }
    for (int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      rotate(card.begin(),card.begin() + p - 1, card.begin() + p + c - 1);
    }
    cout << card[0] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;

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

		vector<int> cards;
		for(int i=0; i<n; i++)
			cards.push_back(i+1);
		int p, c;
		for(int i=0; i<r; i++) {
			cin >> p >> c;
			for(int j=0; j<c; j++) {
				int temp;
				temp = cards[n-p+1-c];
				cards.erase(cards.begin()+n-p+1-c);
				cards.push_back(temp);
			}
		}
		cout << cards[n-1] << endl;
	}
	return 0;
}