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 <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int,int> pii;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
template <class F, class T> void convert(const F &f, T &t){	stringstream ss; ss << f; ss >> t;}


bool solve(){
	int n, r;
	cin>> n>> r;
	if(n==0 && r==0) return false;
	
	int crr = 0, nex = 1;
	vector<vector<int> > a(2, vector<int>(n));
	for(int i=0;i<n;i++) a[crr][i] = n-i;
	
	for(int i=0;i<r;i++){
		int p, c;
		cin>> p>> c;
		for(int j=0;j<n;j++){
			if(j < c){
				a[nex][j] = a[crr][j+p-1];
			}else if(j < c + p - 1){
				a[nex][j] = a[crr][j-c];
			}else{
				a[nex][j] = a[crr][j];
			}
		}
		swap(crr, nex);
		for(int k=0;k<n;k++) cout<< a[crr][k]<<" "; cout<< endl;
	}
	
	cout<< a[crr][0]<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	while(solve());
	return 0;
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i] << endl;
  }
  cout << endl;
}

void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);
  }
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
int main(){
 int i,r,n,p,c;
 for(;scanf("%d%d",&n,&r),n;){
  std::vector<int> v;
  for(i=n;i;i--)v.push_back(i);
  for(i=0;i<r;i++)scanf("%d%d",&p,&c),p--,std::rotate(v.begin(),v.begin()+p,v.begin()+p+c);
  printf("%d\n",v[0]);
 }
}

C++: #include <stdio.h>

int main(){

  int n,r,p,c,i,j;
  int score[51];
  int temp[51];

  for(;;){

    scanf("%d%d",&n,&r);
    if(n==0&&r==0){
      break;
    }

    for(i=1;i<=n;i++){
      score[i]=i;
      temp[i]=i;
    }

    for(i=1;i<=r;i++){
      scanf("%d%d",&p,&c);

      for(j=n-p+1;j>n-p+1-c;j--){
	score[j+p-1]=score[j];
      }
      for(j=n;j>n-p+1;j--){
	score[j-c]=temp[j];
      }

    }

    printf("%d\n",score[n]);
  }
  return 0;

}

C++: #include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int n, r;
	while (cin >> n >> r&&n != 0 && r != 0) {
		list<int>a[2];
		for (int i = n; i >= 1; i--) {
			a[0].push_back(i);
		}
		int p, c;
		list<int>::iterator it = a[0].begin(),it2;
		for (int z = 0; z < r; z++) {
			cin >> p >> c;
			it = a[0].begin();
			a[1].clear();
			for (int i = 1; i < p; i++) it++;
			for (int i = 0; i < c; i++) {
				a[1].push_back(*it);
				it2 = it;
				it2++;
				a[0].erase(it);
				it = it2;
			}
			a[0].insert(a[0].begin(), a[1].begin(), a[1].end());
		}
		it = a[0].begin();
		cout << (*it) << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,r;
	while(cin>>n>>r,n) 
	{
		int deck[n];
		for(int i = 0; i < n; ++i)
		{
			deck[i]=n-i;
		}
		for(int i = 0; i < r; ++i)
		{
			int p,c; cin>>p>>c;
			int tmp[n],now=0;
			for(int j = p-1; j < p-1+c; ++j)
			{
				tmp[now++]=deck[j];	
			}
			for(int j = 0; j < p-1; ++j)
			{
				tmp[now++]=deck[j];	
			}
			for(int j = p-1+c; j < n; ++j)
			{
				tmp[now++]=deck[j];
			}
			for(int i = 0; i < n; ++i)
			{
				deck[i]=tmp[i];
				//cout<<deck[i];
			}
			//cout<<endl;
		}
		cout<<deck[0]<<endl;
	}
  return 0;
}

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

using namespace std;

int main()
{
	int n,r;
	int yama[51];
	int stook[51];

	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int p,c;
		
			for(int i=1;i<=n;i++)
				yama[i]=i;
			
		for(int t=0;t<r;t++){
			cin>>p>>c;
			for(int i=1;i<=p-1;i++)
				stook[i]=yama[n-i+1];
	
			for(int i=1;i<=c;i++)
				yama[n-i+1]=yama[n-p+2-i];

			for(int i=1;i<=p-1;i++)
				yama[n-c-i+1]=stook[i];
		}

			cout<<yama[n]<<endl;
	}
	
	return 0;
}

C++: #include<iostream>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																

	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

C++: #include <iostream>
#include <math.h>
#include <array>
#include <algorithm>
using namespace std;
int n, r, p, c;

int main(){
  while( cin >> n >> r && n > 0){
    int a[50];
    for(int i = 1; i < n+1; i++){
      a[i-1] = i;
    }
    for (int i = 0; i < r; i++){
      cin >> p >> c;
      rotate(a+n+1-c-p, a+n+1-p, a+n);
    }


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


  }




}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];



signed main(){
	IOS();
	ll n, r;
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0)break;
		vector<ll> a(n + 1), a2(n + 1);
		for (int i = 0;i <= n;++i) {
			a[i] = a2[i] = n - i + 1;
		}
		for (int i = 0;i < r;++i) {
			a = a2;
			ll p, c;
			cin >> p >> c;
			for (int i = 0;i < c;++i) {
				a2[i + 1] = a[p + i];
			}
			for (int i = 1;i < p;++i) {
				a2[i + c] = a[i];
			}
		}
		cout << a2[1] << endl;
	}

	return 0;
}