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 main(){
    int n,r;
    while(true){
        cin >> n >> r;
        if(n == 0 && r== 0) break;
        int k[n];
        for(int i=0; i<n; i++)k[i]=n-i;
        int a[r],b[r];
        int c[n];
        for(int i = 0;i < r; i++)cin >> a[i] >> b[i];
        for(int i = 0;i < r; i++){
            for(int j = 0;j < b[i]; j++){
                c[j] = k[a[i]+j-1];
            }
            int d[100];
            for(int j = 0;j < a[i]-1;j++){
                d[j]=k[j];
            }
            for(int j=0;j<a[i]-1;j++){
                k[j+b[i]]=d[j];
            }
            for(int j = 0;j < b[i]; j++){
                k[j] = c[j];
            }
        }
        cout << k[0] << endl;
    }
}

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

int main() {
	int n,r;
	int p,c;
	int a[50];
	int b[50];
	while(1)
	{
		cin>>n>>r;
		if(n==0||r==0)
		{
			break;
		}
		int i=1;
		for(i=0;i<n;i++)
		{
			a[i]=n-i;
			b[i]=0;
		}
		i=0;
		while(r!=i)
		{
			cin>>p>>c;
			int j;
			for(j=0;j<c;j++)
			{
				b[j]=a[j+(p-1)];
			}
			for(j=0;j<p-1;j++)
			{
				b[c+j]=a[j];
			}
			for(j=0;j<(p-1)+c;j++)
			{
				a[j]=b[j];
			}
			i++;
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n, r;
    while(cin >> n >> r && n*r != 0){
        int lst[n];
        for(int i=0; i<n; i++) {
            lst[i] = n-i;
        }
        for(int x=0; x<r; x++){
            int p, c;
            cin >> p >> c;
            if(p == 1) {
            }
            else {
                int sub[c];
                for(int j=0; j<c; j++) {
                    sub[j] = lst[p-1+j];
                }
                for(int k=p-2; k>=0; k--) {
                        lst[k+c] = lst[k];
                }
                for(int i=0; i<c; i++) {
                    lst[i] = sub[i];
                }
            }
        }
        cout << lst[0] << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++)
		after[i]=tmp[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	if((n==0) && (r==0))
		return false;
	for(i=0;i<n;i++)
		before[i]=n-i;	
	return true;
}

void Shuffle(int b[], int a[], int t[]){
	int j;
	for(j=0;j<c;j++){
		a[j]=b[p-1+j];
		t[j]=b[p-1+j];
	}
	for(j=0;j<p-1;j++){
		a[c+j]=b[j];
		t[c+j]=b[j];
	}
	for(j=0;j<n;j++)
		b[j]=t[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after,tmp);
	}
	return after[0];
}


int main(){
  while(init(),input()){
	cout<<solve()<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
        int n,r;
        cin >> n >> r; 
        while(n){
                int in[50][2];
                for(int i = 0; i < r; i++){
                        cin >> in[i][0] >> in[i][1];
                }  
                int m = n; 
                for(int i = r-1; i >= 0; i--){
                        int p = in[i][0];
                        int c = in[i][1];
                        if(n-(p-1)-c >= m) continue;
                        if(n-c < m){
                                m -= p-1;
                        }else{
                                m += c; 
                        }  
                }  
                cout << m << endl;
                cin >> n >> r; 
        }  
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define Reps(i, x, N) for(int i = x; i < N; i++)

const int LLINF = 1LL << 60;


signed main()
{
  int N, R;

  while(cin >> N >> R, N || R) {
    int p, c;
    
    int num[55];
    Rep(i, N) num[i] = N - i - 1;
    
    while(R--) {
      int temp[55];

      cin >> p >> c; --p;
      
      Rep(i, c) temp[i] = num[i + p];
      for(int i = p - 1; i >= 0; i--) num[c + i] = num[i];
      Rep(i, c) num[i] = temp[i];
    }
    cout << num[0] + 1 << endl;
  }

  return 0;
}

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

int main() {
    while(true) {
        int nCard, cycle; cin >> nCard >> cycle;
        if(nCard == 0 && cycle == 0) return 0;
        vector<int> card(nCard);
        for(int i = 0; i < nCard; i++) card[i] = i+1;
        reverse(card.begin(), card.end());

        for(int i = 0; i < cycle; i++) {
            int loc, num; cin >> loc >> num;
            rotate(card.begin(), card.begin()+loc-1, card.begin()+loc-1+num);
        }
        cout << card[0] << endl;
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>

using namespace std;

int main(){

	int n,r,table[50],p,c,work[50];

	while(true){
		scanf("%d %d",&n,&r);
		if(n == 0 && r == 0)break;

		for(int i = 0; i < n; i++){
			table[i] = n-i;
		}

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

			//???????????????????????£???????????????????????????
			for(int k = 0; k < c; k++){
				work[k] = table[p-1+k];
			}

			//?¬???????0???p-2?????§????????????
			for(int k = 0; k < p-1; k++){
				work[c+k] = table[k];
			}

			//????????????p+c-1???n-1?????§????????????
			for(int k = p+c-1; k < n; k++){
				work[k] = table[k];
			}

			for(int k = 0; k < n; k++)table[k] = work[k];
		}

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

	}

    return 0;
}

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

int main(){

    while(1){
        int n, r;
        cin >> n >> r;
        if(n == 0){
            break;
        }

        vector<int> now(n);
        vector<int> next(n);

        for(int i = 0; i < n; i++){
            now[i] = n - i;
        }

        int p, c;
        for(int i = 0; i < r; i++){
            cin >> p >> c;
            for(int j = 0; j < c; j++){
                next[j] = now[p - 1 + j];
            }
            for(int j = 0; j < p - 1; j++){
                next[c + j] = now[j];
            }

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

            swap(now, next);
        }

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

    return 0;
}

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

using namespace std;

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

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

        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;

}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[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[i]=i+1;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[l];
			}
			for(int m=0;m<p-1;m++){
				card[n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int o=0;o<c;o++){
				card[n-c+o]=mem[n-p-c+1+o];
			}
		}
		cout << card[n-1] <<endl;
		

	}
	
	return 0;
}