Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

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

using namespace std;

int cards[55],n;

void init(){
	int i;
	for(i=0; i<n; i++){
		cards[i+1] = (n-i);
	}
}

void shuffle(int p,int c){
	int tmp[55],i;
	for(i=1; i<=n; i++){
		tmp[i] = cards[i];
	}
	for(i=0; i<c; i++){
		cards[i+1] = tmp[p+i];
	}
	for(i=1; i<p; i++){
		cards[c+i] = tmp[i];
	}
}

int main(void){
	int r,i,p,c;
	while(true){
		cin >> n >> r;
		if(n==0 && r==0){
			break;
		}
		init();
		for(i=0; i<r; i++){
			cin >> p >> c;
			shuffle(p,c);
		}
		cout << cards[1] << endl;
	}
	return 0;
}

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

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

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);
  }
}

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);
    }
 
    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;
      } 
      r--;
    }
    cout << root->number << endl;
  }
  return 0;
}

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

int card[1000], tmp[1000], n, r;
int main()
{
loop:
  cin >> n >> r;
  if(!(n || r))
    return 0;
  for(int i = n; i > 0; i--)
    card[n - i] = i;
  for(int i = 0; i < r; i++)
  {
    int c, p;
    cin >> p >> c;
    for(int j = 0; j < p - 1; j++)
      tmp[j] = card[j];
    for(int j = 0; j < c; j++)
      card[j] = card[j + p - 1];
    for(int j = 0; j < p - 1; j++)
      card[j + c] = tmp[j];
  }
  cout << card[0] << endl;
  goto loop;
}

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

using namespace std;

int main() {
    while (1) {
        int n, r;
        cin >> n >> r;
        
        if (n * r == 0) break;
        vector<int> card;
        
        for (int i = 0; i < n; ++i) {
            card.push_back(n - i);
        }

        for (int i = 0; i < r; ++i) {
            int p, c;
            cin >> p >> c;
            for (int k = 0; k < c; ++k) {
                int temp = card[c + p - 2];
                card.erase(card.begin() + c + p - 2);
                card.insert(card.begin(), temp);
            }
        }

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

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

using namespace std;

int N, R, p, c, i, j;

int main()
{
   while ( cin >> N >> R && N >0 )
   {
      int A[N];
      for ( i = 0; i < N; i++)
         {
            A[i] = N - i;
         }
      for ( j = 0; j<R; j++)
         {
            cin >> p >> c;
            rotate(A,A+(p-1),A+(p+c-1));
         }
      cout << A[0] <<endl;
   }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
  if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
       
        }
    }
    cout<<n-card[0]+1<<endl;
  //  ans[counter]=n-card[0];
    counter+=1;
}
    
    
    
int main (){
counter=0;
    while(input()){
    solve();
    }
return 0;
}
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
  if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
       
        }
    }
    cout<<n-card[0]+1<<endl;
  //  ans[counter]=n-card[0];
    counter+=1;
}
    
    
    
int main (){
counter=0;
    while(input()){
    solve();
    }
return 0;
}

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

using namespace std;

int main()
{
  int N, R, p, c;
  // ???????????????????????¨???????????????                                                                                         
  while(cin >> N >> R && N){
    // ?±±?????????                                                                                                         
    array<int, 50> A;
    for(int i=0; i<N; i++){
      A[i] = N - i;
    }
    // ?????£?????????                                                                                                       
    for(int i=0; i<R; i++){
      cin >> p >> c;
      if(p == 1) continue;
      rotate(begin(A), begin(A) + p - 1, begin(A) + p + c - 1);
    }
    cout << A[0] << endl;
  }
}

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

int main(){
  int card[50],tmp[50];
  int n,r,p,c;

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

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

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

C++: #include<stdio.h>

int main() {

	int n, r;
	int array[51];
	int tmp[51];
	while (1) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0) break;

		for (int i = 1; i <= n; i++) {
			array[i] = i;
		}
		for (int i = 0; i < r; i++) {
			int p, c;
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++) {
				tmp[j] = array[n - (p - 1) - j];
			}
			for (int j = 0; j < (p - 1); j++) {
				array[n - (p - 1) - c + 1 + j] = array[n - (p - 1) + 1 + j];
			}
			for (int j = 0; j < c; j++) {
				array[n - c + 1 + j] = tmp[c - 1 - j];
			}
		}
		printf("%d\n", array[n]);
	}
}