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

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m;
struct cards
{
    int from,to;
    cards(int f,int t)
    {
        from=f,to=t;
    }
};
deque<cards> all;
deque<cards> split(int k)
{
    deque<cards> sub;
    for(;;)
    {
        cards t=all.front();
        all.pop_front();
        k -= t.to-t.from+1;
        if(k==0)
        {
            sub.pb(t);
            break;
        }
        if(k<0)
        {
            all.push_front(cards(t.to+k+1,t.to));
            t.to+=k;
            sub.pb(t);
            break;
        }
        sub.pb(t);
    }
    return sub;
}
void shuffle(int x,int y)
{
    deque<cards> a=split(x);
    deque<cards> b=split(y);
    for(int i=0;i<a.size();i++)all.push_front(a[i]);
    for(int i=0;i<b.size();i++)all.push_front(b[i]);
}
int main()
{
    while(1)
    {
        cin >> n >> m;
        if(n==0&&m==0)break;
        all.clear();
        all.pb(cards(1,n));
        for(int i=0;i<m;i++)
        {
            int p,c;
            cin >> p >> c;
            shuffle(p-1,c);
        }
        cout << n-all[0].from+1 << endl;
    }
    return 0;
}

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

int main(){
    int card[51];
    int tmp[50];
    int n,r, from, num;

    while(1){
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        for(int i=1; i<=n; i++){
            card[i]=n-i+1;
        }
        for(int i=0; i<r; i++){
            cin >> from >> num;
            for(int j=0; j<num; j++){
                tmp[j] = card[from+j];
            }
            for(int j=from-1; j>0; j--){
                card[j+num] = card[j];
            }
            for(int j=0; j<num; j++){
                card[j+1] = tmp[j];
            }
        }
        cout << card[1] << endl;
    }
        
    return 0;
}

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

int main(){
  int n=1,r=1,p,c;
  vector<int> deck,temp,ans;

  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=n; i>0; --i)deck.push_back(i); //???????????????
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      copy(deck.begin()+p-1,deck.begin()+p+c-1,back_inserter(temp));
      deck.erase(deck.begin()+p-1,deck.begin()+p+c-1);
      copy(deck.begin(),deck.end(),back_inserter(temp));
      deck=temp;
      temp.clear();
    }
    ans.push_back(deck[0]);
    deck.clear();
  }
  for(auto && x: ans)cout << x << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using Int = int64_t;

int main() {
   for(;;) {
      Int n, r;
      std::cin >> n >> r;
      if( n == 0 and r == 0 ) break;
      std::vector<Int> xs(n);
      for(Int i = 0; i < n; ++i) {
         xs[i] = n - i;
      }
      for(Int i = 0; i < r; ++i) {
         Int p, c;
         std::cin >> p >> c;
         std::vector<Int> ys(n);
         for(Int k = 0; k < c; ++k) {
            ys[k] = xs[k+p-1];
         }
         for(Int k = c; k < c+p-1; ++k) {
            ys[k] = xs[k-c];
         }
         for(Int k = p-1+c; k < n; ++k) {
            ys[k] = xs[k];
         }
         xs = ys;
      }
      std::cout << xs[0] << std::endl;
   }
}