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>
#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;
                        for(int j=0; j<n; j++) {
                                huda[i]=n-i;
                                huda2[i]=huda[i];
                        }
                        for(int j=0; j<c; j++) {
                                huda[j]=huda[p1-1+j];
                        }
                        for(int j=0; j<p1-1; j++) {
                                huda[c+j]=huda2[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}

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

using namespace std;

int main()
{
	int n, r;
	while(cin >> n >> r){
		if(n==0 && r==0) break;
		vector<int> huda;
		for(int i=0;i<n;i++){
			huda.push_back(n-i);
		}
		/*
		for(int i=0;i<n;i++){
			cout<<huda[i]<<endl;
		}
		*/
		for(int i=0;i<r;i++){
			int p, c;
			cin >> p >> c;
			vector<int> temp;
			for(int j=0;j<c;j++){
				temp.push_back(huda[p-1+j]);
			}
			/*
			for(int i=0;i<temp.size();i++){
				cout<<temp[i]<<endl;
			}
			cout<<endl;
			*/
			for(int j=p-1+c-1;j>0;j--){
				huda[j]=huda[j-1];
			}
			
			for(int j=0;j<c;j++){
				huda[j]=temp[j];
			}
			
		}
		/*
		for(int i=0;i<n;i++){
			cout<<huda[i]<<endl;
		}
		cout <<endl;
		*/
		cout << huda[0] << endl;
	}
	return 0;
}

C++: #include <iostream>


using namespace std;

int main(){
	int n,r;
	while(cin >> n >> r,n){
		int ds[n];
		for(int i = 0;i < n;i++) ds[i] = n - i;
		int p,c;
		for(int i = 0;i < r;i++){
			cin >> p >> c;
			int sds[n];
			p--;
			for(int t = p;t < p + c;t++) sds[t-p] = ds[t];
			for(int t = 0;t < p;t++) sds[t+c] = ds[t];
			for(int t = 0;t < p + c;t++) ds[t] = sds[t];
		}
		cout << ds[0] << endl;
	}
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[50][50]={0};
	int mem[50]={0};
	int n;
	int r;
	int k = 0 ;
	int p,c;
	while(1){
		cin >>n >>r;
		if ((n==0)&&(r==0)) break;
		for(int i =0;i<n;i++){
			card[k][i]=i;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[k][l];
			}
			for(int m=0;m<p-1;m++){
				card[k][n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int l=0;l<c;l++){
				card[k][n-c+l]=mem[n-p-c+1+l];
			}
		}
		cout << card[k][n-1] <<endl;
		k++;

	}
	
	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 <iostream>
#include <cassert>
#include <deque>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define MAX 50
using namespace std;
int ans;
int n,r,c,p;
deque<int> deck;
int main() {
  while(1){
    cin >> n >> r;
    if(n==0&&r==0) return 0;
    deck.clear();
    rep(i,n) deck.push_front(i+1);
    rep(i,r){
      cin >> p >> c;
      rep(j,c){
        deck.push_front(deck[p-1+c-1]);
        deck.erase(deck.begin()+p-1+c);
      }
    }
    ans = deck[0];
    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
	int n = 0;
	int r = 0;
	int p = 0;
	int c = 0;

	int deck[50];
	int tmp[50];

	while (true)
	{
		cin >> n;
		cin >> r;
		if (n == 0 && r == 0)break;
		for (int i = 0; i < n; i++)
		{
			deck[i] = n - i;
		}

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

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

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

			for (int j = c; j < c + p; j++)
			{
				deck[j] = tmp[j - c];
			}
		}
		cout << deck[0] << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){
	while(1){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a==0)return 0;
		int e[50];
		for(int i=0;i<a;i++){
			e[i]=a-i;
		}
		for(int i=0;i<b;i++){
			int c,d;
			int f[50];
			scanf("%d%d",&c,&d);
			int j;
			for(j=0;j<d;j++){
				f[j]=e[c+j-1];
			}
			for(;j<c+d-1;j++){
				f[j]=e[j-d];
			}
			for(;j<a;j++){
				f[j]=e[j];
			}
			for(int j=0;j<a;j++)e[j]=f[j];
		}
		printf("%d\n",e[0]);
	}
}

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

int main(void)
{
  int n,r;

  for(;;){
    scanf("%d %d",&n,&r);
    if(n==0)return 0;

    int fuda[n];
    for(int i=0;i<n;i++)
      fuda[i]=n-i;
    
    int p,c;

    for(int i=0;i<r;i++){
      scanf("%d %d",&p,&c);//3 1

      int fuda_tmp[p+c-1];
      for(int j=0;j<=p+c-2;j++)
	fuda_tmp[j]=fuda[j];
    
      //printf("%d\n",fuda[0]);
      //printf("\n");

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

      //for(int j=0;j<n;j++){printf("%d\n",fuda[j]);}
      
    }

  
    printf("%d\n",fuda[0]);
  }

  return 1;
}

C++: #include <iostream>

using namespace std;

int main(){
	int n, r;
	int card[50];
	while(cin >> n >> r, 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, card+p-1, card+p+c-1);
		}
		cout << card[0] << endl;
	}
}