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>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	while (1) {
		int n, r;
		int p, c;
		int a[51] = {};
		int b[51] = {};
		
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}
		FOR(i, 1, n) {
			a[i] = n - i + 1;
		}
		FOR(i, 1, r) {
			cin >> p >> c;
			FOR(t, 1, p - 1) {
				b[t] = a[t];
			}
			FOR(t, 1, c) {
				a[t] = a[p + t - 1];
			}
			FOR(t, 1, p - 1) {
				a[c+t] = b[t];
			}
		}
		cout << a[1] << endl;
	}

}

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

int main()
{
  int n,r;
  int i,j,k;
  int p,c;
  int a[60];//a[0]??????
  int b[60];
  int x;

  while(1){
    cin>>n>>r;
    if(n==0 && r==0)break;
    puts("");
    for(i=0;i<n;i++)
      a[i]=n-i;

    for(i=0;i<r;i++){
      cin>>p>>c;
      for(j=0;j<c;j++)//c??????????????????
	b[j]=a[p-1+j];
      for(k=0;k<p-1;k++)//p-1???????????¨???
	b[j+k]=a[k];
      for(x=0;x<j+k;x++)//??????????????????
	a[x]=b[x];      
    }    
    cout<<a[0]<<endl;
  }
}

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

int main(){
	int n,r;
	while(cin>>n>>r,n,r){
		vector<int>v;
		for(int i=0;i<n;i++){
			v.push_back(i+1);
			}
			
			for(int i=0;i<r;i++){
				int p,c;
				cin>>p>>c;
				
				for(int i=0;i<c;i++){
					v.push_back(v[n-c-p+1]);
					v.erase(v.begin()+n-c-p+1);
					}
				}
		cout<<v[n-1]<<endl;			
		}
		return 0;
	}

C++: #include<stdio.h>
int main()
{
  int j,i,n,p,c,r,ss=0;
  int N[100000],C[10000],X[10000];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0 && r==0)break;
    for(i=0;i<n;i++){
      N[i]=i+1;
    }
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=0;j<c;j++){
	C[j]=N[n-p-j];
      }
      for(j=n-p+1;j<n;j++){
        N[j-c]=N[j];
      }
      for(j=0;j<c;j++){
        N[n-j-1]=C[j];
      }
      
    }
    /* for(i=0;i<n;i++){
      printf("%d ",N[i]);
      }*/
    X[ss]=N[n-1];
    ss++;
  }
  for(i=0;i<ss;i++){
    printf("%d\n",X[i]);
    }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector> 
using namespace std;
int main(){
  int n, r, p, c;
  

  while(1){
    
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    int i;
    int a[n], temp[n];
    for(i = 1;i < n+1;i++){
      a[n-i] = i;
    }

    for(int j = 0;j < r;j++){
      cin >> p >> c;
      
      
      
      for(i = 0;i < c;i++){
        temp[i] = a[p-1+i];
        //cout << "temp[n-p-c+i] = " << temp[n-p-c+i] << "a[n-p-1+i] = " << a[n-p-1+i] << endl;
      }
      for(i = 0;i < p-1;i++){
        temp[c+i] = a[i];
      } 
      for(i = 0;i < n-p-c+1;i++){
        temp[c+p-1+i] = a[c+p-1+i];
      }
      for(i = 0;i < n;i++){
        a[i] = temp[i];
      }
      
    }
    
    cout << temp[0] << endl;

  }

  return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[n];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
		}
		for(int i=0; i<r; i++){
			cin >> p;
			cin >> c;
			int tmp[c];
			for(int i=0; i<c; i++){
				tmp[i] = huda[p+i-1];
			}
			for(int i=p-2; i>=0; i--){
				huda[i+1] = huda[i];
			}
			for(int i=0; i<c; i++){
				huda[i]=tmp[i];	
			}
		}
		cout << huda[0] << "\n";
	}
}

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

int main(){
  int n, r;
  while((cin >> n >> r), n,r){
    string s="",t="",u="", v="";
    for(int i=n; i>=1; i--){
      s+=i+'0';
    }
    for(int i=0; i<r; i++){
      int x, y;
      cin >> x >> y;
      t = s.substr(x-1,y);
      u = s.substr(x+y-1,s.length());
      v = s.substr(0,x-1);
      s = t+v+u;
    }
    cout << s[0] << endl;
  }

  return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

    int n, r;
    while(cin >> n >> r, n) {
        vector< int > card(n);
        for(int i = 0; i < n; i++)
            card[i] = n - i;
        while(r--) {
            int p, c; cin >> p >> c;
            vector< int > temp(c);
            p--;
            for(int cnt = 0, i = p; i < p + c; i++, cnt++)
                temp[cnt] = card[i];
            for(int i = p - 1; i >= 0; i--)
                card[i + c] = card[i];

            for(int i = 0; i < c; i++) {
                //cout << card[i] << " " << temp[i] << endl;
                card[i] = temp[i];
            }

        }

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

C++: #include <stdio.h>

int cards[50];
int N,R;

int swap(int p, int c)
{
    int t_cards[50];
    for(int i=0; i < N; i++)
        t_cards[i] = cards[i];
    for(int i=0; i < c; i++)
        cards[i] = cards[p-1+i];
    for(int i=0; i < p-1; i++)
        cards[i+c] = t_cards[i];
    return 0;
}

int main(void)
{
    while(true)
    {
        scanf("%d%d", &N, &R);
        if(N==0 && R==0) break;

        for(int i=0; i < N; i++)
            cards[i] = N-i;

        for(int i=0; i < R; i++)
        {
            int p,c;
            scanf("%d%d", &p, &c);
            swap(p, c);
        }
        printf("%d\n", cards[0]);
    }

    return 0;
}

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

using namespace std;

int main() {
    int n, r;

    for (;;) {
        cin >> n >> r;
        if (n == 0 && r == 0) break;

        // init
        vector<int> cards(n);
        for (int i = 0; i < n; i++) cards[i] = n - i;

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

            vector<int> cards_(cards);
            for (int j = 0; j < c; j++) cards[j] = cards_[j + p - 1];
            for (int j = 0; j < p - 1; j++) cards[j + c] = cards_[j];

        }

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