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>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int main(){
    int n,r;
    while(cin >> n >> r,n) {
        vi card(n);
        rep(i,n) card[i] = n - i;
        rep(i,r){
            int p,c;
            cin >> p >> c;
            vi tmp(c);
            rep(j,c) tmp[j] = card[p - 1 + j];
            rrep(j,p) card[j + c - 1] = card[j - 1];
            rep(j,c) card[j] = tmp[j];
        }
        cout << card[0] << endl;
    }
    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 - 1; i < n; i++){
        cs.push_back(cards[i]);
      }

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

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

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

using namespace std;


int main(){

	int n,r;
	while(cin >> n >> r && !(n == 0 && r == 0)){
		int pile[51];
		for(int i = 0; i < n; i++){
			pile[i] = i+1;
		}
		for(int i = 0; i < r; i++){
			int p,c;
			cin >> p >> c;
			int tmp[51];
			for(int j = 0; j < c; j++){
				tmp[j] = pile[n-1-j-(p-1)];
			}
			for(int j = p-1; j > 0; j--){
				pile[n-1-(j-1)-c] = pile[n-1-(j-1)];
			}
			for(int j = 0; j < c; j++){
				pile[n-1-j] = tmp[j];
			}
		}
		cout << pile[n-1] << endl;
		
	}

	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n,r;
	while(cin>>n>>r,(n!=0&&r!=0)){
		vector<P> h(r);
		rep(i,r)cin>>h[i].first>>h[i].second;

		stack<int> s;
		repi(i,1,n+1)s.push(i);

		rep(i,r){
			stack<int> p,c;
			rep(j,h[i].first-1){
				int x=s.top();s.pop();
				p.push(x);
			}
			rep(j,h[i].second){
				int x=s.top();s.pop();
				c.push(x);
			}
			rep(j,h[i].first-1){
				int x=p.top();p.pop();
				s.push(x);
			}
			rep(j,h[i].second){
				int x=c.top();c.pop();
				s.push(x);
			}
		}
		cout<<s.top()<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
void init(int *a, int b){
  for(int i=1;i<=b;i++){
    a[i]=b-i+1;
  }
}

int main(int argc, char *argv[])
{
  int n, r;
  int p, c;
  int hanafuda[51];
  int tmp[51];
  while(1){
    cin >> n >> r;
    if(n+r==0){
      return 0;
    }
    init(hanafuda, n);
    for(int i=0;i<r;i++){
      cin >> p >> c;

      for(int k=1;k<p;k++){
        tmp[c+k]=hanafuda[k];
      }

      for(int k=p;k<p+c;k++){
        tmp[k-p+1]=hanafuda[k];
      }

      for(int l=1;l<c+p;l++){
        hanafuda[l]=tmp[l];
      }
    }

    cout << hanafuda[1] << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

void cut(int[],int,int);

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		int card[n];
		for(int i=0;i<n;i++)
			card[i]=n-i;

		for(int i=0;i<r;i++){
			cin >> p >> c;
			if(p!=1)
				cut(card,p,c);
		}

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

	return 0;
}

void cut(int card[],int p,int c){
	int tmp[c];

	for(int i=0;i<c;i++)
		tmp[i]=card[p-1+i];

	for(int i=0;i<p;i++)
		card[p+c-2-i]=card[p-2-i];

	for(int i=0;i<c;i++)
		card[i]=tmp[i];
}

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

int d[50];
int n, r;

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

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

struct list{
  int number;
  list *next;
};

void Insertlist(list **ptr, int newnumber);
void Traverselist(list *ptr);


void Insertlist(list ** ptr, int newnumber){
  if( *ptr == NULL || (*ptr)->number < newnumber){
    list *newcell;
    newcell = (list *)malloc(sizeof(list));
    newcell->number = newnumber;
    newcell->next = *ptr;
    *ptr = newcell;
  }else{
    Insertlist(&(*ptr)->next, newnumber);
  }
}

void Traverselist(list *ptr){
  while(ptr!= NULL){
    cout << ptr->number << " \n";
    ptr = ptr->next;
  }
}


int main(){

  int n, r;

  while( cin >> n >> r ){

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

    list *root = NULL;
    for(int i = n ; i > 0 ; i--){
      Insertlist(&root,i);
    }
    //       Traverselist(root);    

    while( r ){
      int p,c;
      cin >> p >> c;

      list *ptr1 = root, *ptr2 = root,*ptr3,*ptr4;

	for(int i = 0 ; i < p-2; i++)
	  ptr1 = ptr1->next;
	if(p > 1)
	  ptr2 = ptr1->next;
	ptr3 = ptr2;
	for(int i = 0; i < c-1 ; i++)
	  ptr3 = ptr3->next;
	ptr4 = ptr3->next;

	if(p>1){
	  ptr1->next = ptr4;
	  ptr3->next = root;
	  root = ptr2;
	}
	//   Traverselist(root);    
	r--;
    }
    cout << root->number << endl;
    
  }
  return 0;
}

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

using namespace std;

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		string card;

		for(int i=0;i<n;i++)
			card+=(n-i+0x30);

		for(int i=0;i<r;i++){
			cin >> p >> c;
			if(p!=1)
				card = card.substr(p-1,c)+card.substr(0,p-1)+card.substr(p+c-1);
		}

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

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

   while(1){

      int n, r;
      cin>> n>> r;
      if(n==0&&r==0) break;
      int a[n];
      for(int i=0; i<n; i++) a[i]=n-i;
      for(int i=0; i<r; i++){
         int p, c;
         cin>> p>> c;
         int b[c];
         for(int j=p-1; j<p+c-1; j++){
            b[j-(p-1)]=a[j];
         }
         for(int j=p+c-1; j>c-1; j--){
            a[j]=a[j-c];
         }
         for(int j=0; j<c; j++){
            a[j]=b[j];
         }
         for(int A: a){
            cout<< A<<" ";
         }cout<< endl;
      }

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

C++: #include<cstdio>
using namespace std;
int num1[50],num2[50];
void sets(int N);
void change(int p,int c);
int main()
{
    int N,r,i,j,p,c;
    for(;scanf("%d%d",&N,&r),N+r!=0;)
    {
        sets(N);
        for(i=0;i<r;i++)
        {
            scanf("%d%d",&p,&c);
            change(p,c);
        }
        printf("%d\n",num2[0]);
    }
    return 0;
}
void sets(int N)
{
    for(int i=0,j=N;i<N;i++,j--)
    {
        num1[i]=j;
    }
}
void change(int p,int c)
{
    int i;
    for(i=0;i<p-1;i++)num2[c+i]=num1[i];
    for(i=0;i<c;i++)num2[i]=num1[p-2+i];
}