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<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    while(true){
        int n, r;
        cin >> n >> r;
        if(n == 0 && r == 0){
            break;
        }
        vector<int> fuda(n);
        for(int i = 0 ; i < n ; i++){
            fuda[i] = n - i;
        }
        for(int i = 0 ; i < r ; i++){
            int x, y;
            cin >> x >> y;
            x--;
            for(int j = 0 ; j < y ; j++){
                int tmp = fuda[x + j];
                fuda.erase(fuda.begin() + x + j);
                fuda.insert(fuda.begin() + j, tmp);
            }
        }
        cout << fuda[0] << endl;
    }
    return 0;
}

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

int main()
{
    int card_num;
    int shuffle_num;
    int p, c;
    while(1){
        cin >> card_num;
        cin >> shuffle_num;
        if(card_num * shuffle_num == 0){
            break;
        }
        int card[card_num];
        for(int i = 0; i < card_num; i++){
            card[i] = card_num - i;
        }
        for(int i = 0; i < shuffle_num; i++){
            cin >> p;
            cin >> c;
            rotate(card, card + p - 1, card + c + p - 1);
        }
        cout << card[0] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r){
		if(n==0&&r==0)break;
		int card[50];
		int tmp1[50],tmp2[50];
		for(int i=0;i<n;++i)card[i]=i+1;
		for(int i=0,p,c;i<r;++i){
			cin>>p>>c;
			for(int j=0;j<p;++j)tmp1[j]=card[j];
			for(int j=p;j<p+c;++j)tmp2[j]=card[j];
			for(int j=0;j<c;++j)card[j]=tmp2[j];
			for(int j=c;j<c+p;++j)card[j]=tmp1[j];
		}
		cout<<(card[0])<<"\n";
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std; 
int main(){
  int n,r;
  int a[60]={}; 
  while(cin>>n>>r){
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++){
      a[i]=n-i;
    }
    int b[60]={};
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      for(int j=0;j<c;j++){
	b[j]=a[p-1+j];	
      }
      for(int j=0;j<p-1;j++){
	b[j+c]=a[j];
      }
      for(int j=0;j<n-p-c;j++){
	b[j+p+c-1]=a[j+p+c-1];
      }

      for(int i=0;i<n;i++){	
	a[i]=b[i];
      }
    }
    cout<<b[0]<<endl;
  }  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		string str;
		for(int i=n;i>0;i--)str+=i-'0';
		for(int i=0,p,c;i<m;i++){
			string now;
			cin>>p>>c;
			for(int j=0;j<c;j++)now+=str[p-1+j];
			for(int j=0;j<n;j++)if(j<p-1||j>p+c-2)now+=str[j];
			str=now;
		}
		cout<<str[0]+'0'<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

vector<int> shuffle(vector<int> a, int p, int c, int n)
{
  vector<int> b;

  FOR(i,p-1,p+c-1) b.push_back(a[i]);
  FOR(i,0,p-1) b.push_back(a[i]);
  FOR(i,p+c-1,n) b.push_back(a[i]);

  //REP(i,n) cout<<b[i]<<" ";

  return b;
}

int solve(int n,int r)
{
  vector<int> a;
  int p, c;

  REP(i,n) a.push_back(n-i);
  //REP(i,n) cout<<a[i]<<" ";

  REP(i,r){
    cin>>p>>c;
    a = shuffle(a, p, c, n);
  }

  return a[0];
}

int main()
{
  int n, r;

  while(1) {
    cin>>n>>r;
    if (n == 0 && r == 0) break;
    cout<<solve(n,r)<<endl;
  }


  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r,p1,c;
int huda[51],huda2[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>p1>>c;
                        for(int j=0; j<n; j++) {
                                huda[i]=n-i;
                                huda2[i]=huda[i];
                        }
                        for(int j=0; j<c; j++) {
                                huda[j]=huda[p1-1+j];
                        }
                        for(int j=0; j<p1-1; j++) {
                                huda[c+j]=huda2[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}

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

using namespace std;

int main()
{
	int n, r;
	while(cin >> n >> r){
		if(n==0 && r==0) break;
		vector<int> huda;
		for(int i=0;i<n;i++){
			huda.push_back(n-i);
		}
		/*
		for(int i=0;i<n;i++){
			cout<<huda[i]<<endl;
		}
		*/
		for(int i=0;i<r;i++){
			int p, c;
			cin >> p >> c;
			vector<int> temp;
			for(int j=0;j<c;j++){
				temp.push_back(huda[p-1+j]);
			}
			/*
			for(int i=0;i<temp.size();i++){
				cout<<temp[i]<<endl;
			}
			cout<<endl;
			*/
			for(int j=p-1+c-1;j>0;j--){
				huda[j]=huda[j-1];
			}
			
			for(int j=0;j<c;j++){
				huda[j]=temp[j];
			}
			
		}
		/*
		for(int i=0;i<n;i++){
			cout<<huda[i]<<endl;
		}
		cout <<endl;
		*/
		cout << huda[0] << endl;
	}
	return 0;
}

C++: #include <iostream>


using namespace std;

int main(){
	int n,r;
	while(cin >> n >> r,n){
		int ds[n];
		for(int i = 0;i < n;i++) ds[i] = n - i;
		int p,c;
		for(int i = 0;i < r;i++){
			cin >> p >> c;
			int sds[n];
			p--;
			for(int t = p;t < p + c;t++) sds[t-p] = ds[t];
			for(int t = 0;t < p;t++) sds[t+c] = ds[t];
			for(int t = 0;t < p + c;t++) ds[t] = sds[t];
		}
		cout << ds[0] << endl;
	}
}

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

	}
	
	return 0;
}