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 <iostream>
using namespace std;
int n,r,p,c;
int main(){
	while(cin>>n>>r){
		if(n==0&&r==0) break;
		int a[n],b[n];
		for(int i=0;i<n;i++){
			a[i]=n-i;
			b[i]=n-i;
		}
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=0;j<c;j++){
				a[j]=b[p+j-1];
			}
			for(int j=0;j<p;j++){
				a[c+j]=b[j];
			}
			for(int j=0;j<n;j++){
				b[j]=a[j];
			}
		}
		cout<<a[0]<<endl;
	}
    return 0;
}

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

#define INF 1000000007LL
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)

int n,r,p[55],c[55];

int main(){
	while(cin>>n>>r && n){
		rep(i,r)cin>>p[i]>>c[i];
		int x=1;
		for(int i=r-1;i>=0;i--){
			if(x<=c[i])x+=p[i]-1;
			else if(x<=c[i]+p[i]-1)x-=c[i];
		}
		cout<<n+1-x<<endl;
	}
}

C++: //#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int input(char s[]);

int main() {
	int n, r,brk=0,p,c,x[50],xs[50];
	for (int i = 0; i < 50; i++)
		x[i] = xs[i] = i;

	while (1) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0)
			brk = 1;
		for (int i = 0; i < r&&brk == 0; i++) {
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++)
				x[j] = xs[j + p - 1];
			for (int j = c; j < c + p - 1; j++)
				x[j] = xs[j - c];
			for (int j = 0; j < n; j++)
				xs[j] = x[j];}
		if (brk == 1)
			break;
			printf("%d\n", n-x[0]);
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int main(){
    int n,r;
    while(cin >> n >> r,n) {
        vi card(n);
        rep(i,n) card[i] = n - i;
        rep(i,r){
            int p,c;
            cin >> p >> c;
            vi tmp(c);
            rep(j,c) tmp[j] = card[p - 1 + j];
            rrep(j,p) card[j + c - 1] = card[j - 1];
            rep(j,c) card[j] = tmp[j];
        }
        cout << card[0] << endl;
    }
    return 0;

}

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

using namespace std;

int32_t main()
{
  while(true){
    uint32_t n, r;
    cin >> n >> r;
    if(n == 0) break;

    vector<uint32_t> cards(51, 0);
    for(int32_t i = n-1, j = 1;  i >= 0; i--, j++){
      cards[i] = j;
    }

    for(uint32_t i = 0; i < r; i ++){
      uint32_t p, c;
      cin >> p >> c;
      vector<uint32_t> cs;
      for(uint32_t i = p - 1; i < p - 1 + c; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = 0; i < p - 1; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = p - 1 + c - 1; i < n; i++){
        cs.push_back(cards[i]);
      }

      for(uint32_t i= 0; i < n; i++){
        cards[i] = cs[i];
      }
    }

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

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

using namespace std;


int main(){

	int n,r;
	while(cin >> n >> r && !(n == 0 && r == 0)){
		int pile[51];
		for(int i = 0; i < n; i++){
			pile[i] = i+1;
		}
		for(int i = 0; i < r; i++){
			int p,c;
			cin >> p >> c;
			int tmp[51];
			for(int j = 0; j < c; j++){
				tmp[j] = pile[n-1-j-(p-1)];
			}
			for(int j = p-1; j > 0; j--){
				pile[n-1-(j-1)-c] = pile[n-1-(j-1)];
			}
			for(int j = 0; j < c; j++){
				pile[n-1-j] = tmp[j];
			}
		}
		cout << pile[n-1] << endl;
		
	}

	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n,r;
	while(cin>>n>>r,(n!=0&&r!=0)){
		vector<P> h(r);
		rep(i,r)cin>>h[i].first>>h[i].second;

		stack<int> s;
		repi(i,1,n+1)s.push(i);

		rep(i,r){
			stack<int> p,c;
			rep(j,h[i].first-1){
				int x=s.top();s.pop();
				p.push(x);
			}
			rep(j,h[i].second){
				int x=s.top();s.pop();
				c.push(x);
			}
			rep(j,h[i].first-1){
				int x=p.top();p.pop();
				s.push(x);
			}
			rep(j,h[i].second){
				int x=c.top();c.pop();
				s.push(x);
			}
		}
		cout<<s.top()<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
void init(int *a, int b){
  for(int i=1;i<=b;i++){
    a[i]=b-i+1;
  }
}

int main(int argc, char *argv[])
{
  int n, r;
  int p, c;
  int hanafuda[51];
  int tmp[51];
  while(1){
    cin >> n >> r;
    if(n+r==0){
      return 0;
    }
    init(hanafuda, n);
    for(int i=0;i<r;i++){
      cin >> p >> c;

      for(int k=1;k<p;k++){
        tmp[c+k]=hanafuda[k];
      }

      for(int k=p;k<p+c;k++){
        tmp[k-p+1]=hanafuda[k];
      }

      for(int l=1;l<c+p;l++){
        hanafuda[l]=tmp[l];
      }
    }

    cout << hanafuda[1] << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

void cut(int[],int,int);

int main(void){
	int p,c;

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

		for(int i=0;i<r;i++){
			cin >> p >> c;
			if(p!=1)
				cut(card,p,c);
		}

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

	return 0;
}

void cut(int card[],int p,int c){
	int tmp[c];

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

	for(int i=0;i<p;i++)
		card[p+c-2-i]=card[p-2-i];

	for(int i=0;i<c;i++)
		card[i]=tmp[i];
}

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

int d[50];
int n, r;

int main() {
  while (1) {
    scanf("%d%d", &n, &r);
    if (n == 0) break;
    for (int i = 0; i < n; i++) d[i] = n - i;
    int p, c;
    int temp[50];
    for (int i = 0; i < r; i++) {
      scanf("%d%d", &p, &c);
      p--;
      for (int j = 0; j < c; j++) temp[j] = d[j + p];
      for (int j = 0; j < p; j++) temp[j + c] = d[j];
      for (int j = 0; j < p + c; j++) d[j] = temp[j];
    }
    printf("%d\n", d[0]);
  }
}