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])
	}
}

Python: while True:
    n,r=map(int,input().split())
    if n==0:exit()
    l=[n-i for i in range(n)]
    for j in range (r):
        p,c=map(int,input().split())
        l=l[p-1:p+c-1]+l[:p-1]+l[p+c-1:]
    print(l[0])

Python: while True:
    n, r = map(int, input().split())
    if (n,r) == (0,0):
        break
    else:
        cards = [i for i in range (1, n+1)]
        cards.reverse()
        for i in range (r):
            p,c = map(int,input().split())
            top = cards[0 : p-1]
            mid = cards[p-1 : p+c-1]
            btm = cards[p+c-1:]
            cards = mid + top + btm
        print(cards[0])

Python: while True:
    n, r = map(int, input().split())
    if n + r < 1:
        break
    mountain = list(range(1, n+1))
    for i in range(r):
        p, c = map(int, input().split())
        mountain = mountain[:n-p-c] + mountain[p-1:] + mountain[-(p-1+c):-(p-1)]
    print(mountain[-1])

Python: while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break
    cards = [i + 1 for i in range(n)]
    cards.reverse()
    for _ in range(r):
        p, c = map(int, input().split())
        new_cards = cards[p - 1 :p - 1 + c] + cards[0:p - 1] + cards[p - 1 + c:]
        cards = new_cards
    print(cards[0])

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

using namespace std;

int main(){
  int n,r;
  while(cin >> n >> r,n+r){
    int buff1[n];
    int buff2[n];
    int *cards=buff1,*next=buff2;

    /* initialize */
    for(int i=0;i<n;i++){
      cards[i]=n-i;
    }

    /* operation */
    while(r --> 0){
      int p,c,m;
      cin >> p >> c;
      m=c;

      for(int i=0;i<n;i++){
        if(i>=p-1 && i<p+c-1){
          /* to the top */
          next[i-p+1]=cards[i];
        }else{
          /* not to the top */
          next[m++]=cards[i];
        }
      }
      swap(cards,next);
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,r,p,c;
    while(cin>>n>>r,n){
        vector<int> v(n,0);
        iota(v.rbegin(),v.rend(),1);
        for(int i=0;i<r;i++){
            cin>>p>>c;
            vector<int> t(c,0);
            for(int j=0;j<c;j++){
                t[j]=v[j+p-1];
            }
            for(int j=p-1;j>0;j--){
                v[c+j-1]=v[j-1];
            }
            for(int j=0;j<c;j++){
                v[j]=t[j];
            }
        }
        cout<<v[0]<<endl;
    }
}

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

using namespace std;

int main(){
	int n, r, p, c;
	int *before, *after;
	while(cin >> n >> r && n){
		before = new int[n];
		after = new int[n];
		for(int i=0; i<n; i++) before[i]=n-i, after[i]=n-i;
		for(int i=0; i<r; i++){
			cin >> p >> c;
			for(int i=0; i<c; i++) after[i] = before[p-1+i];
			for(int i=0; i<p-1; i++) after[c+i] = before[i];
			for(int i=0; i<n; i++) before[i]=after[i];
		}
		cout << after[0] << endl;
		delete[] after;
		delete[] before;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, r, p, c;
V v;

int main(){
	while (cin >> n >> r&&n + r){
		REP(i, n){
			v.push_back(n - i);
		}
		REP(i, r){
			cin >> p >> c;
			V t;
			REP(i, c){
				t.push_back(v[p - 1 + i]);
			}
			REP(i, p - 1){
				t.push_back(v[i]);
			}
			FOR(i, p - 1 + c, n){
				t.push_back(v[i]);
			}
			v = t;
		}
		cout << v[0] << endl;
		v.clear();
	}
}

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

int main()
{
	int n, r, card[51], temp[51];
	while (cin >> n >> r, n || r){

		//初期化
		for (int i = 0; i < n; i++){
			card[i] = n - i;
		}

		//入力と操作
		for (int i = 0; i < r; i++){
			int p, c;
			cin >> p >> c;

			//tempにコピー
			for (int i = 0; i < p - 1 + c; i++)
				temp[i] = card[i];

			//上からc個
			for (int i = 0; i < c; i++){
				card[i] = temp[p - 1 + i];
			}

			//上からp個
			for (int i = 0; i < p - 1; i++){
				card[c + i] = temp[i];
			}
		}

		//出力
		cout << card[0]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

constexpr int MAX = 50;

int main (int argc, char *argv[]) {
    int n, r, p, c;
    vector<int> h;
    int i, j;
    
    // input
    while (cin>>n>>r, n||r) {
        // init
        for (i = 0, j = 1; i < n; ++i, ++j) {
            h.push_back(j);
        }

        // solve
        for (i = 0; i < r; ++i) {
            // cout<<"-----init------"<<endl;
            // for (int i = n-1; i > -1; --i) {
            //     cout<<i<<":"<<h[i]<<endl;
            // }

            cin>>p>>c;

            int p_ = n - p;
            int c_ = p_ - (c - 1);

            // copy
            vector<int> tmp;
            for (int i = 0; i < c; ++i) {
                tmp.push_back(h[c_]);
                c_++;
            }

            // cout<<"---tmp---"<<endl;
            // for (int i = c-1; i >= 0; --i) {
            //     cout<<tmp[i]<<endl;
            // }

            // erase
            c_ = p_ - (c - 1);
            h.erase(h.begin() + c_, h.begin() + c_ + c);

            // cout<<"-----erase------"<<endl;
            // // for (int i = n-1; i > -1; --i) {
            // //     cout<<h[i]<<endl;
            // // }
            // for (auto e : h) {
            //     cout<<e<<endl;
            // }
        
            // copy
            for (int i = 0; i < c; ++i) {
                h.push_back(tmp[i]);
            }

            tmp.clear();
        }

        // cout<<"-----init------"<<endl;
        // for (int i = n-1; i > -1; --i) {
        //     cout<<h[i]<<endl;
        // }

        // cout<<"---ans---"<<endl;
        cout<<h[n-1]<<endl;
        
        // clear
        h.clear();
    }
    return 0;
}

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

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++)
		after[i]=tmp[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	for(i=0;i<n;i++)
		before[i]=n-i;	
	return 1;
}

void Shuffle(int b[], int a[], int t[]){
	int j;
	for(j=0;j<c;j++){
			a[j]=b[p-1+j];
			t[j]=b[p-1+j];
		}
		for(j=0;j<p;j++){
			a[c+j]=b[j];
			t[c+j]=b[j];
		}
		for(j=0;j<n;j++)
			b[j]=t[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after,tmp);
	}
	return after[0];
}


int main(){
	n=r=1;
  while((n!=0)&&(r!=0)){
	init(),input();
	cout<<solve()<<endl;
  }
  return 0;
}