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 <list>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int n,r;

	cin >> n;
	cin >> r;

	while (n != 0 || r != 0) {
		std::list<int> lst;
		int now = 1;

		for (int i = 0; i < n; i++) {
			lst.push_back(i+1);
		}

		for (int i = 0; i < r; i++) {
			int index = 1;
			int p,c;
			cin >> p;
			cin >> c;

			for (std::list<int>::iterator itr = lst.begin(); itr != lst.end();) {
				if (index >  n-(p-1)-c && index < n-(p-2) && r != n){
					lst.push_back(*itr);
					itr = lst.erase(itr);
				}else{
					itr++;
				}	
				index++;
			}
		}
		for (std::list<int>::iterator itr = lst.begin(); itr != lst.end(); ++itr) {
			if (now == n) {
				cout << *itr << "\n";
			}
			now++;
		}
		cin >> n;
		cin >> r;
	}	
	return 0;
}

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

int N, R, p, c;

void show(vector<int> v){
    for (int i = 0; i < N; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

int main(){
    while (cin >> N >> R && N){
        vector<int> card(N);
        for (int i = 0; i < N; i++){
            card[i] = N - i;
        }
        //cout << "初期入力"<< endl;
        //show(card);

        for (int i = 0; i < R; i++){
            cin >> p >> c;
            rotate(card.begin(), card.begin()+p-1, card.begin()+p+c-1);
            //cout << i+1 << "回目のrotate" << endl;
            //show(card);
        }
        cout << card[0] << endl;
    }
}

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

int m[4][4];

int main(){
	int i,j;
	int n,r,p,c;
	int f[51],buf[51];
	while(cin >> n >> r,(n||r)){
		for(i=1;i<=n;i++){
			f[i]=-i+n+1;
		}
		while(r--){
			cin >> p >> c;
			for(i=1;i<p;i++) buf[i]=f[i];	//buf
			for(i=1;i<=c;i++) f[i]=f[i+p-1];
			for(i=1;i<p;i++) f[i+c]=buf[i];
		}
		cout << f[1] << endl;
	}
	return 0;
}

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

int main(){
  int n;
  int r;
  while(cin>>n>>r && n+r){
    vector<int> vec;
    vec.resize(n);
    for(int i=0;i<n;i++){
      vec[i]=n-i;
    }

    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      p--;
      vector<int> v;
      v.resize(c);
      for(int j=0;j<c;j++){
	v[j]=vec[p+j];
      }
      for(int j=p-1;j>=0;j--){
	vec[j+c]=vec[j];
      }
      for(int j=0;j<c;j++){
	vec[j]=v[j];
      }
    }
    cout<<vec[0]<<endl;

  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int ans[1000];
int n,r,counter;
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;
    }
    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];
    counter++;
}
 
 
 
int main (){
    counter=0;
    while(input()){
    solve();
    }
    for(int i=0;i<counter;i++){
    cout<<ans[i]<<endl;
    }
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
typedef long long ll;

int N, R, P[50], C[50];
int a[51][50];

int main(void) {
  while(cin >> N>>R, N || R) {
    REP(i, 0, R)cin >>P[i]>>C[i];
    REP(i, 0, N) a[0][i] = N - i;
    REP(i, 0, R){
      REP(j, 0, C[i]) a[i + 1][j] = a[i][P[i] + j - 1];
      REP(j, 0, P[i] - 1) a[i + 1][C[i] + j] = a[i][j];
      REP(j, C[i] + P[i] - 1, N) a[i + 1][j] = a[i][j];
      // REP(j, 0, N) {
      //     cout << a[i + 1][j] << " ";
      // }
      // cout << endl;
    }
    cout << a[R][0] << endl;
  }

  return 0;
}

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

int main(){
  int n, r;
  while((cin >> n >> r), n,r){
    string s="",t="",u="", v="";
    for(int i=n; i>=1; i--){
      s+=i+'0';
    }
    for(int i=0; i<r; i++){
      int x, y;
      cin >> x >> y;
      t = s.substr(x-1,y);
      u = s.substr(x+y-1,s.length());
      v = s.substr(0,x);
      s = t+v+u;
    }
    cout << s[0] << endl;
  }

  return 0;
}

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

int main(){
  int n,r;
  int array1[50],array2[50];

  while(1){
    cin>>n>>r;
    if(n+r==0)break;

    for(int i=0;i<n;i++) array1[n-i-1]=array2[n-i-1]=i+1;

    for(int j=0;j<r;j++){
      int c,p;
      cin>>c>>p;

      for(int i=0;i<p;i++){
	swap(array1[c-1+i],array1[i]);
	array2[c-1+1]=0;
      }
      
      for(int i=p;i<n;i++){
	if(array2[i]==0)i++;
	array1[i]=array2[i-p];
      }

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

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int n, r;
  while(scanf("%d%d", &n, &r) && n+r){
    vector<int>vi(n);
    int t = n;
    rep(i, n) vi[i] = t--;
    int p, c;
    while(r--){
      scanf("%d%d", &p, &c);
      p--;
      vector<int>tmp;
      rep(i, c){
	tmp.push_back(vi[p]);
	vi.erase(vi.begin()+p);
      }
      vi.insert(vi.begin(), tmp.begin(), tmp.end());
      /*      puts("");
      rep(i, n){
	printf("%d ", vi[i]);
	}*/
    }
    printf("%d\n", vi[0]);
  }
  return 0;
}

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


int card[50];
struct CUT{
  int p;
  int c;
};

CUT cut[51];
int swap_p[50];
int swap_c[50];
int n,r;
void solve(){
  for(int i = 0; i < n; i++){
    card[i] = n - i;
  }

  for(int i = 0; i < r ; i++){
   /* for(int x = 0; x < n; x++){
      cout << card[x] << " ";
    }
    cout << endl;
    */
    for(int j = 0; j < cut[i].p; j++) swap_p[j] = card[j];
    for(int k = 0; k < cut[i].c; k++) swap_c[k] = card[cut[i].p + k - 1];
    for(int l = 0; l < cut[i].p + cut[i].c - 1;l++){
      if(cut[i].c > l)  card[l] = swap_c[l] ;
      else              card[l] = swap_p[ l - cut[i].c ];
    }
  }
  cout << card[0] << endl;
  return ;
}



int main(){
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    for(int input = 0; input < r; input++){
      cin >> cut[input].p >> cut[input].c ;
    }
    solve();
  }
  return 0;
}