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 <bits/stdc++.h>
using namespace std;

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


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

        stack<int> st;
        for(int i=1; i<=n; i++) st.push(i);

        for(int i=0; i<r; i++){
            int p, c;
            cin >> p >> c;
            vector<int> v1;
            vector<int> v2;
            for(int j=0; j<p-1; j++){
                v1.push_back(st.top());
                st.pop();
            }
            for(int j=0; j<c; j++){
                v2.push_back(st.top());
                st.pop();
            }
            for(int j=0; j<p-1; j++){
                st.push(*(v1.end()-1));
                v1.pop_back();
            }
            for(int j=0; j<c; j++){
                st.push(*(v2.end()-1));
                v2.pop_back();
            }
        }

        cout << st.top() << endl;

    }
}

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define iter(c) __typeof((c).begin())
#define each(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define URU(y) (!(y % 4) && y % 100 || !(y % 400))

using namespace std;

typedef pair<int, int> PII;
typedef long long LINT;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;

int dx[] = { 0, 0, -1, 1 }, dy[] = { -1, 1, 0, 0 };
//int dx[] = { 0, 0, -1, 1, -1, 1, -1, 1 }, dy[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
//int dx[] = { 1, 1, 0, -1 }, dy[] = { 0, 1, 1, 1 };

int main ( void )
{
	// cin.tie( 0 );
	// ios::sync_with_stdio( false );
	int n, r;
	while ( cin >> n >> r, n | r ) {
		VI cards( n );
		for ( int i = 0; i < n; ++i ) {
			cards[i] = n - i;
		}
		for ( int i = 0; i < r; ++i ) {
			VI t( cards );
			int p, c;
			cin >> p >> c;
			for ( int j = 0; j + 1 < p; ++j ) {
				t[c + j] = cards[j];
			}
			for ( int j = 0; j < c; ++j ) {
				t[j] = cards[p - 1 + j];
			}
			cards = t;
		}
		cout << cards[0] << endl;
	}
	return 0;
}

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

int main(){
    int n,r;
    for(int i = 0;;i++){
        scanf("%d%d",&n,&r);
        if(n == 0 && r == 0){
            break;
        }
        int hanafuda[n];
        for(int j = 0;j < n;j++){
            hanafuda[j] = j + 1;
        }
        for(int j = 0;j < r;j++){
            int p,c;
            scanf("%d%d",&p,&c);
            if(c == n){
                continue;
            }
            for(int k = 0;k < c;k++){
                for(int K = 0;;K++){
                    if(p - k + K == n){
                        break;
                    }
                    std::swap(hanafuda[p - k + K - 1],hanafuda[p - k + K]);
                }
            }
        }
        printf("%d\n",hanafuda[n - 1]);
    }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s

int main()
{
	int n, r;
	while (cin >> n >> r, n)
	{
		int p, c;
		vector<int> deck;
		vector<int> tmp;
		REP(i, n) deck.push_back(n - i);
		REP(s, r)
		{
			tmp = deck;
			cin >> p >> c;
			REP(i, c)
			{
				deck[i] = tmp[p + i - 1];
			}
			REP(i, p - 1)
			{
				deck[i + c] = tmp[i];
			}

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

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

using namespace std;

void solve(stack <int> s , int r ){
  
  
  int p[r] ,c[r];

  for(int i = 0 ; i < r ; i++ ){
    cin >> p[i] >> c[i];
    p[i]--;
  }
  
  for(int i = 0 ; i < r ; i++ ){
    stack<int> s_sita;
    stack<int> s_ue;
    
    

    while(p[i]-- > 0){
      int a = s.top();
      s.pop();
      //cout << "push_sita:" << a << endl;
      //cout << "p:" << p[i] << endl;
      //cout << "size" << s.size() << endl;
      s_sita.push(a);
    }

    while(c[i]-- > 0){
      int a =s.top();
      s.pop();
      //cout << "push_ue:" << a << endl;
      //cout << "c" << c[i] << endl;
      //cout << "size" << s.size() << endl;
      s_ue.push(a);
    }
    
    while(!s_sita.empty()){
      s.push(s_sita.top());
      //cout << "s.push" << s_sita.top() << endl;
      s_sita.pop();
    }
    
    while(!s_ue.empty()){
      s.push(s_ue.top());
      //cout << "s.push" << s_ue.top() << endl;
      s_ue.pop();
    }
    
    //cout << "size" << s.size() << endl;

    //cout << endl;

  }
    
  cout << s.top() << endl;

  return;

}

int main(){

  int r , n ;

  
  while(1){

    cin >> n >> r;
    if(r == 0 || n == 0)
      break;

    else{
      stack <int> s;
      for(int i = 1 ; i <= n ; i++ ){
        s.push(i);
        //cout << i << endl;
      }
      solve(s,r);
      //cout << "done" << endl;
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
int  main(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(n==0&& r==0) break;
    int a[51],b[51];
    lp(i,51){
      a[i]=i;
    }
    lp(i,r){
      lp(j,51){
	b[j]=0;
      }
      int c,d;
      cin>>c>>d;
      for(int j=n;j>n-c+1;j--){
	b[j-d]=a[j];
      }
      for(int j=n-c+1;j>n-c-d;j--){
	b[j+c-1]=a[j];
      }
      for(int j=1;j<=n;j++){
	if(b[j]!=0){
	  a[j]=b[j];
	}
      }
    }
    cout<<a[n]<<endl;
  }
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)

int n, m;
int data[100];

void shuffle(int x, int y){
  int dst[100];
  for(int i=x-1;i<x-1+y;++i){
    dst[i-x+1]=data[i];
  }
  for(int i=x-2;i>=0;--i){
    data[i+y]=data[i];
  }
  for(int i=0;i<y;i++){
    data[i]=dst[i];
  }
}

void init(){
  rep(i,n)
    data[i]=n-i;
}

int main() {
  while(true){
    scanf("%d%d",&n,&m);
    if (!n&&!m)break;
    init();
    rep(_,m) {
      int x, y;
      scanf("%d%d",&x,&y);
      shuffle(x,y);
    }
    printf("%d\n",data[0]);
  }
  return 0;
}