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 <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int n, r;
  while (cin >> n, cin >> r, n && r) {
    vector<int> card;
    for (int i = 0; i < n; i++) {
      card.push_back(i);
    }
    for (int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      p--;
      for (int j = n-p-c; j < n-p; j++) {
        card.push_back(card[j]);
      }
      card.erase(card.begin() + n-p-c, card.begin() + n-p);
      for (int j = 0; j < card.size(); j++) {
        //cerr << card[j]+1 << " ";
      }
      //cerr << endl;
    }

    cout << card.back() +1 << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n,m;
  while(cin>>n>>m,n+m){
    string in;
    rep(i,n)in = (char)(i) + in;
    //rep(i,n)cout<<int(in[i]+1)<<endl;
    rep(i,m){
      int a,b;
      cin>>a>>b;
      in = in.substr(a-1,b)+in.substr(0,a-1)+in.substr(a+b-1);
    }
    cout<<int(in[0]+1)<<endl;
  }
  
}

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

int main(void)
{
	while ( true ) {
		std::vector<int> yama;
		int n, r;

		std::cin >> n;
		std::cin >> r;

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

		yama.resize(n);

		for ( int i = 0; i < n; ++i ) {
			yama[i] = i + 1;
		}

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

			int b = n - p;

			std::vector<int> d(c);

			for ( int j = 0; j < c; ++j ) {
				d[c - j -1] = yama[b - j];
			}

			for ( int j = b; j < n; ++j ) {
				yama[j - c] = yama[j];
			}

			for ( int j = n - c; j < n; ++j ) {
				yama[j] = d[j - n + c];
			}
			for ( int i = 0; i < n; ++i ) {
				std::cout << yama[i] << std::endl;
			}
		}

		std::cout << yama[n - 1] << std::endl;
	}
	return 0;
}

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

int main() {
	int n, r;
	while(cin >> n >> r) {
		if(n == 0 && r == 0)
			break;
		vector<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;
			rotate(a.begin(), a.begin()+p-1, a.begin()+p+c-1);
			//for(int j = 0; j < n; j++) {
			//	cout << a[j] << ",";
			//}
			//cout << endl;
		}
		cout << a[0] << endl;
	} 
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,r;
    while (cin>>n>>r) {
        if (n==0&&r==0) {
            break;
        } else {
            std::deque<int> deq;
            for (int i=n;i>0;i--) {
                deq.emplace_back(i);
            }
            int p,c;
            for (int i=0;i<r;i++) {
                cin>>p>>c;
                std::deque<int> tmp;
                for (int i=0;i<c;i++) {
                    tmp.emplace_back(deq[p-1]);
                    deq.erase(deq.begin()+p-1,deq.begin()+p);
                }
                for (int i=tmp.size()-1;i>=0;i--) {
                    deq.emplace_front(tmp[i]);
                }
            }
            cout<<deq[0]<<endl;
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,r;
    while(cin>>n>>r,r){
        int a,b;
        vector<int> v;
        for(int i=0;i<n;i++){
            v.push_back(n-i-1);
        }
        for(int x:v){
                //cout <<x<<" ";
            }
            //cout<<endl;
        for(int i=0;i<r;i++){
            cin>>a>>b;
            vector<int> tmp=v;
            for(int j=0;j<a-1;j++){
                for(int k=0;k<n;k++){
                    if(tmp[k]==j){
                        v[k]+=b;
                    }
                }
            }
            for(int j=0;j<b;j++){
                for(int k=0;k<n;k++){
                    if(tmp[k]==j+a-1){
                        v[k]-=a-1;
                    }
                }
            }
            for(int x:v){
                //cout <<x<<" ";
            }
            //cout<<endl;
            
        }
        for(int i=0;i<n;i++){
            if(v[i]==0)cout<<i+1<<endl;
        }
    }
}

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

int main(void){
  while(true){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0){ break; }

    int p, c;
    vector<int> hanafuda(n);
    for(int i = 0; i < n; i++){ hanafuda[i] = n - i; }
    for(int i = 0; i < r; i++){
      cin >> p >> c;
      --p;
      vector<int> tmp;
      for(int j = p; j < p + c; j++){ tmp.push_back(hanafuda[j]); }
      for(int j = p - 1; j >= 0; j--){ hanafuda[j + c] = hanafuda[j]; }
      for(int j = c - 1; j >= 0; j--){ hanafuda[j] = tmp[j];}
    }
    cout << hanafuda[0] << endl;
  }
  return 0;
}

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


int card[50];
struct CUT{
  int p;
  int c;
};

CUT cut[51];
int swap_p[50];
int swap_c[50];
int n,r;
void solve(){
  for(int i = 0; i < n; i++){
    card[i] = n - i;
  }
/*
  for(int i = 0; i < r ; i++){
    for(int x = 0; x < n; x++){
      cout << card[x] << " ";
    }
    cout << endl;
    */
    for(int j = 0; j < cut[i].p; j++) swap_p[j] = card[j];
    for(int k = 0; k < cut[i].c; k++) swap_c[k] = card[cut[i].p + k - 1];
    for(int l = 0; l < cut[i].p + cut[i].c - 1;l++){
      if(cut[i].c > l)  card[l] = swap_c[l] ;
      else              card[l] = swap_p[ l - cut[i].c ];
    }
  }
  cout << card[0] << endl;
  return ;
}



int main(){
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    for(int input = 0; input < r; input++){
      cin >> cut[input].p >> cut[input].c ;
    }
    solve();
  }
  return 0;
}

C++: #include <vector>
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
    int n, r;
    int p, c;
    int up[100] = {}, down[100] = {};

    while(cin >> n >> r, n){
        vector<int> cards;
        rep(i, n){
            cards.push_back(n - i);
        }
        rep(i, r) {
            cin >> p >> c;
            rep(j, p-1){
                up[j] = cards[j];
            }
            rep(j, c){
                down[j] = cards[p - 1 + j];
            }
            rep(j, c){
                cards[j] = down[j];
            }
            rep(j, p-1){
                cards[c + j] = up[j];
            }            
        }
        cout << cards[0] << endl;
    }

    return 0;
}

C++: #include<stdio.h>

int main(){

int n,r;
while(1){
scanf("%d%d",&n,&r);if(n==0&&r==0)break;
int N[52]={};int N2[52]={};
for(int i=1;i<=n;i++){
N[i]=1+n-i;N2[i]=1+n-i;}



for(int i=0;i<r;i++)
{int p,c;
scanf("%d%d",&p,&c);
for(int j=1;j<p;j++){
N2[j+c]=N[j];
}

for(int j=p;j<p+c;j++){
N2[j-p+1]=N[j];
}
for(int j=0;j<=n;j++)
N[j]=N2[j];

}
printf("%d\n",N2[1]);
}
return 0;
}