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>
#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; i < n; i++){
        cs.push_back(cards[i]);
      }

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

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

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

using namespace std;

void solve()
{
	int n, r;
	while(cin >> n >> r, n , r)
	{
		int p, c;
		stack<int> data;
		stack<int> buf1;
		stack<int> buf2;
		for(int i = 1; i <= n; ++i)
		{
			data.push(i);
		}
		while(r--)
		{
			cin >> p >> c;
			for(int i = 0; i < p - 1; ++i)
			{
				buf1.push(data.top());
				data.pop();
			}
			for(int i = 0; i < c; ++i)
			{
				buf2.push(data.top());
				data.pop();
			}
			int size1 = buf1.size();
			int size2 = buf2.size();
			for(int i = 0; i < size1; ++i)
			{
				data.push(buf1.top());
				buf1.pop();
			}
			for(int i = 0; i < size2; ++i)
			{
				data.push(buf2.top());
				buf2.pop();
			}
		}
		cout << data.top() << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
    int n,r;
    cin>>n >>r;
    if(n==0&&r==0)  break;
    int cards[n-1];
    REP(i,n){
      cards[i] = (n-i);
    }
    int help[100]={0};
    int p[100];
    int c[100];
    REP(i,r){
      cin>>p[i]>>c[i];
      REP(j,c[i]){
	help[c[i]-j-1] = cards[p[i]+c[i]-2-j];
      }
      for(int j=0;(p[i]-1-j)>=0;j++){
	if((p[i]-1-j)<0) break;
	cards[p[i]+c[i]-2-j] = cards[p[i]-2-j];
      }
      REP(j,c[i]){
	cards[j]=help[j];
      }
    }
    cout << cards[0] << endl;
  }
  return 0;
}

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

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

	//while (1) {
	for (cnt=0; cnt<10000; cnt++) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0)
			brk = 1;
		if (brk == 1)
			break;
		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];}
			ans[cnt] = n - x[0];
	}
	for (int i = 0; i < cnt; i++)
		printf("ans:%d\n", ans[i]);
	return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  while(1){
    int n,r; cin >> n >> r;
    if(n == 0) break;
    vi a(n);
    rep(i,n) a[i] = n-i;
    rep(i,r){
      int p,c; cin >> p >> c;
      vi C(c);
      FOR(j,p-1,p+c-1) C[j-p+1] = a[j];
      ROF(j,p-1,0) a[j+c] = a[j];
      rep(j,c) a[j] = C[j];
    }
    cout << a[0] << endl;
  }      
}

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

int main(){

	int n, r;
	while(cin >> n >> r, n|r){
		vector<int> now(100), next(100);
		for(int i=0; i<n; i++){
			now[n-1-i] = i+1;
		}
		for(int i=0; i<r; i++){
			int p, c; cin >> p >> c;
			for(int j=0; j<n; j++){	
				if(j<c){
					next[j] = now[p-1+j];
				}else if(j<c+p){
					next[j] = now[j-c];
				}else{
					next[j] = now[j];
				}
			}
			now = next;
		}
		cout << now[0] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int x[100];
int y[100];
int card [100];
int ans[100];
int n,r,counter;
int main (){
    counter=0;
    while(input()){
    solve();
    }
for(int i=0;i<counter;i++){
cout<<ans[i]<<endl;
}
return 0;
}
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
    if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
        }
    }
    ans[counter]=n-card[0]+1;
    counter++;
}

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

int main()
{
  int n, r;
  while( cin >> n >> r, n && r ) {
    int card[51];
    for(int i=n-1; i>=0; i--) card[i] = n-i-1;

    while( r-- ) {
      int p, c;
      int tmp[51];
      cin >> p >> c;
      for(int i=0; i<n; i++) tmp[i] = card[i];

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

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

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  while(1){
    int n,r,a,b,yama[51],tmp[51];
    cin>>n>>r;
    if(n+r==0)break;
    for(int i=0;i<=n;i++)yama[i]=i;
    for(int i=0;i<r;i++){
      cin>>a>>b;
      for(int j=0;j<b;j++)tmp[j]=yama[n-(a+b-2)+j];
      for(int j=0;j<a-1;j++)yama[n-(a+b-2)+j]=yama[n-a+2+j];
      for(int j=0;j<b;j++)yama[n-b+1+j]=tmp[j];
    }
    cout<<yama[n]<<endl;
  }
  return 0;
}

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

signed main() {
	while (true) {
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		vector<int> a(n);

		for (int i = 0; i < n; i++) a[i] = i + 1;

		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			rotate(a.end() - (p - 1) - c, a.end() - (p - 1), a.end());
		}

		cout << a[n - 1] << endl;
	}
}