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++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (true) {
        int n,r; cin >> n >> r;
        if (n == 0 && r == 0) break;
        vector<vector<int>> card(r+1, vector<int>(n));
        rep(i,n) card[0][i] = n-i;
        rep(i,r) {
            int p,c; cin >> p >> c;
            rep(j,n) {
                if (j < c) {
                    card[i+1][j] = card[i][j+p-1];
                } else if (c <= j && j < p-1+c) {
                    card[i+1][j] = card[i][j-c];
                } else card[i+1][j] = card[i][j];
            }
        }
        cout << card[r][0] << endl;
    }
}

C++: #include <stdio.h>
#include<stdlib.h>
#define MAX 51
struct node{int x; struct node* next;};

void initcard(struct node *p){
  p = NULL;
  return;
}
struct node* push_card(struct node *p,int n){
  struct node *x;
  x = (struct node*)malloc(sizeof(struct node));
  x->x = n;
  x->next = p;
  p = x;
  return p;
}

struct node* cut(struct node *q,int p,int c){
  struct node *head,*tail,*b;
  int i;
  if(p==1)return q;
  head = q;
  //printf("%d",q->x);
  for(i=1;i<p-1;i++)q = q->next;
  tail = q;//一番下になる
  b = q->next;//一番上になる
  for(i=0;i<c;i++)q=q->next;
  tail->next = q->next;
  q->next = head;
  return b;
}

void c_free(struct node* p){
  struct node *a;
  while(p!=NULL){
    p = p->next;
    a = p;
    free(a);
  }
  return;
}
int main(){
  struct node *card;
  int i,j,n,r,p,c,m[MAX],str[MAX];
  scanf("%d %d",&n,&r);
  while(n){
    card = NULL;
    for(i=1;i<=n;i++)card = push_card(card,i);
    /*while(card!=NULL){
      printf("%d ",card->x);
      card=card->next;
    }
    printf("\n");*/
      for(j=0;j<r;j++){
        scanf("%d %d",&p,&c);
        card = cut(card,p,c);
        /*while(card!=NULL){
          printf("%d ",card->x);
          card=card->next;
        }
        printf("\n");*/
      }
      printf("%d\n",card->x);
      scanf("%d %d",&n,&r);
    }
      return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 52;
int before[MAXN], after[MAXN];

int main()
{
    int n, r, p, c;
    while(cin >> n >> r && (n && r))
    {
        for(int i = n; i > 0;i--) before[n - i] = i;

        REP(r)
        {
            cin >> p >> c;

            rep(j,p) after[c + j] = before[j];
            rep(j,c) after[j] = before[p - 1 + j];
            rep(j,MAXN) before[j] = after[j];
        }
        cout << before[0] << endl;
    }
    return 0;
}

C++: #include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem1129 : Hanafuda Shuffle **/
int main()
{
	int card[50];
	int n, r, p, c;
	
	while (cin >> n >> r, n||r) {
		
		rep(i, n)
		card[i]=n-i;
		
		rep(k, r) {
			int tmp[n];
			cin >> p >> c;
			
			rep(i, p-1) {
				tmp[i] = card[i];
			}
			rep(i, c) {
				card[i] = card[i+p-1];
			}
			rep(i, p) {
				card[i+c] = tmp[i];
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<string>

using namespace std;


int main(){

	while(1){
		int n,r;	
		cin >> n >> r;
		if(n==0&&r==0) break;
		vector<int> huda(n);
		for(int i=0;i<n;i++) huda[i]=n-i;
		
		for(int i=0;i<r;i++){
			int p,c;
			cin >> p >> c;
			p--;c--;
			for(int j=c;j>=0;j--){
				int a = huda[p+c];
				huda.erase(huda.begin()+p+c);
				huda.insert(huda.begin(),a);
			}
		}

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

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int n,r;
  while(cin>>n>>r,n!=0||r!=0){
  int A[n];
  rep(i,n){
    A[i]=n-i;
  }
  rep(i,r){
    int p,c;
    cin>>p>>c;
    vector<long long> v(c);
    for(int j=p-1;j<p+c-1;j++){
      v[j-(p-1)]=A[j];
    }
    for(int j=p-2;j>=0;j--){
      A[j+c]=A[j];
    }
    for(int j=0;j<c;j++){
      A[j]=v[j];
    }
  }
  cout<<A[0]<<endl;
  }
 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[j]=huda2[j+p1];
                        }
                        for(int j=0; j<p1; j++) {
                                huda2[j+c]=huda[j];
                        }
                        for(int j=0; j<n; j++) {
                                huda[j]=huda2[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}

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

int main() {

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

  return 0;
}