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 <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int n, r;
  while(1) {
    cin >> n >> r;
    if(n==0 && r==0) break;
    int num[n+1];
    FOR(i,0,n+1) num[i] = i;
    while(r--) {
      int p, c;
      scanf("%d %d\n", &p, &c);
      int tmp[c+p];
      FOR(i,0,c) {
        tmp[i] = num[n-p+1-i];
      }
      FOR(i,c,c+p) {
        tmp[i] = num[n-i+c];
      }
      FOR(i,0,c+p) num[n-i] = tmp[i];
    }
    printf("%d\n", num[n]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<ll,ll> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{   
    int n,r;
    while(cin>>n>>r,n!=0)
    {
        stack<int>l;stack<int>cc;stack<int>pp;
        REP(i,n)l.push(i+1);
        REP(i,r)
        {
            int p,c;
            cin>>p>>c;
            REP(j,p-1)
            {
                pp.push(l.top());l.pop();
            }
            REP(j,c)
            {
                cc.push(l.top());l.pop();
            }
            REP(j,p-1)
            {
                l.push(pp.top());pp.pop();
            }
            REP(j,c)
            {
                l.push(cc.top());cc.pop();
            }
        }
        cout<<l.top()<<endl;
    }
}

C++: #include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define fori(i,k,n) for(int i=k;i<n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };



int main()
{
	int r, l;
	cin >> l >> r;
	while (1)
	{
		if (l == r&&r == 0)break;
		vector<int> h;
		for (int i = l; i >=1; i--)h.push_back(i);
		for (int i = 0; i < r; i++)
		{
			vector<int> now;
			int p, c;
			cin >> p >> c;
			for (int k = p - 1; k < p - 1 + c; k++)
			{
				now.push_back(h[k]);
			}
			for (int k = 0; k < p - 1; k++)
			{
				now.push_back(h[k]);
			}
			for (int k = p - 1 + c; k < h.size(); k++)
			{
				now.push_back(h[k]);
			}
			for (int k = 0; k < h.size(); k++)
			{
				h[k] = now[k];
			}
		}
		cout << h[0] << endl;
		cin >> l >> r;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int data[50], n, r, p, c, tmp[50], next[50];

main(){
  while(cin >> n >> r && (n|r)){
    for(int i=0;i<n;i++) data[i] = n-i;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=0;j<p-1;j++) tmp[j] = data[j];
      for(int j=0;j<c;j++) next[j] = data[p-1+j];
      for(int j=0;j<p-1;j++) next[c+j] = tmp[j];
      for(int j=p+c-1;j<n;j++) next[j] = data[j];
      for(int j=0;j<n;j++) data[j] = next[j];
    }
    cout << data[0] << endl;
  }
}

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

using namespace std;


int main()
{
	int n,r,p,c;

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

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

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;

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

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

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

int main(){
  int n, r;
  int p, c;
  vector<int> card;
  vector<int> store;

  while(true){
    cin >> n >> r;

    if(n == 0 && r == 0) break;

    for(int i=n; i>0; i--){
      card.push_back(i);
      store.push_back(0);
    }
  
    for(int i=0; i<r; i++){
      cin >> p >> c;      
    
      int start = p;
      int count = 0;
      for(int j=p; j<p+c; j++){
	store[count++] = card[p-1];
      }

      count = 0;
      for(int j=c; j<n+1; j++){
	if(j <= p)	
	  store[j] = card[p - p + count++];
	else 
	  store[j] = card[j];
      }    

      for(int j=0; j<n; j++)
	card[j] = store[j];
    }

    cout << card.front() << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
using namespace std;

int main(){
	int n=1,r=1;
	int i,j;
	int c,p;
	cin>>n>>r;
	while(!(n==0&&r==0)){
		int x[100];
		queue<int> q;
	
	//cout<<n<<" "<<r<<endl;
	for(i=1;i<=n;i++){
		x[i] = i;
	}
	for(i=0;i<r;i++){
		cin>>p>>c;
		for(j=0;j<c;j++){
			q.push(x[n-p+1-j]);
		}
		for(j=0;j<p;j++){
			q.push(x[n-j]);
		}
		for(j=0;j<p+c;j++){
			x[n-j]=q.front();
			q.pop();
		}
	}
	cout<<x[n]<<endl;
		cin>>n>>r;
	}
	return 0;
}

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

int main(){
  int n,r,p,c,a[50];
  while(1){
    cin>>n>>r;
    if(n==0 && r==0)break;

    for(int i=n;i>0;i--){
      a[n-i]=i;
    }
    for(int i=0;i<r;i++){
    cin>>p>>c;
    rotate(a,a+p-1,a+p+c-1);
    }
    
  cout<<a[0]<<endl;
  }
  return 0;
}