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 <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
using namespace std;

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read_n(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> void write(const T &t) { cout << t << endl; }
struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

/// template end ///

int main()
{
	while (true)
	{
		READ(int, n, r);
		if (!n && !r) { break; }
		deque<int> deck;
		REP(i, n) deck.push_back(n - i);

		REP(i, r)
		{
			READ(int, p, c); p--;
			vector<int> cut(RANGEOF(deck, p, c));
			deck.erase(RANGEOF(deck, p, c));
			deck.insert(deck.begin(), ALLOF(cut));
		}
		write(deck.at(0));
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r;
  while(cin >> n >> r,n){
    vector<int> a(n);
    for(int i=0; i<n; i++) a[i] = n-i;

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

      vector<int> v1,v2;
      for(int j=0; j<p-1; j++) v1.push_back(a[j]);
      for(int j=0; j<c; j++) v2.push_back(a[j+p-1]);
      for(int j=0; j<c; j++) a[j] = v2[j];
      for(int j=0; j<p-1; j++) a[j+c] = v1[j];
    }
    cout << a[0] << endl;
  }
  return 0;
}

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

int main() {
	int n,r;//1~50
	int p,c;
	int card[50]={};
	int cut[50]={};
	int i,j;
	int finish=0;
	
	scanf("%d%d",&n,&r);
	while(finish==0){
	for(i=0;i<n;i++){
		card[i]=n-i;
//		printf("0\t %d\n",card[i]);
	}
	for(j=0;j<r;j++){
		scanf("%d%d",&p,&c);
		for(i=0;i<c;i++){
			cut[i]=card[p+i-1];
//			printf("1\t %d\n",cut[i]);
		}
		for(i=p-2;i>-1;i--){
			card[i+c]=card[i];
//			printf("2\t %d\n",card[i]);
		}
		for(i=0;i<c;i++){
			card[i]=cut[i];
		}
	}
//	for(i=0;i<n;i++){
//		printf("3\t %d\n",card[i]);
//	}
	printf("%d\n",card[0]);
	scanf("%d%d",&n,&r);
	if((n==0)&&(r==0)){finish=1;}
	}
	return 0;
}

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

int main(){
	while(1){
		int n,r;
		std::cin>>n>>r;
		if(n==0&&r==0)break;
		std::vector<int>v;
		std::vector<int>Av;
		for(int i=n;i>=1;i--)v.push_back(i);
		for(int i=0;i<r;i++){
			int p,c;
			std::cin>>p>>c;
			for(int j=p-1;j<p-1+c;j++)Av.push_back(v[j]);
			//for(int j=0;j<Av.size();j++)std::cout<<Av[j]<<std::endl;
			for(int j=p-1+c;j>=c;j--)v[j]=v[j-c];
			for(int j=0;j<Av.size();j++)v[j]=Av[j];
			Av.clear();
		}
		std::cout<<v[0]<<std::endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#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 ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, r;
	while (cin >> n >> r, n){
		vector<int> card(n);
		REP(i, n)
			card[i] = n-i;
		REP(i, r){
			int l, m;
			cin >> l >> m;
			l--;
			vector<int> card2(m);
			copy(card.begin() + l, card.begin() + l + m, card2.begin());
			card.erase(card.begin() + l, card.begin() + l + m);
			card2.insert(card2.end(), card.begin(), card.end());
			card = card2;
		}
		cout << card[0] << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, r;
    while(cin >> n >> r, n | r){
        vector<int> v(n);
        for (int i = 0; i < n; ++i) {
            v[i] = n-i;
        }
        for (int i = 0; i < r; ++i) {
            int p, c;
            cin >> p >> c;
            vector<int> u(c+p-1);
            for (int j = 0; j < c+p-1; ++j) {
                u[(j+c)%(c+p-1)] = v[j];
            }
            for (int j = 0; j < c+p-1; ++j) {
                v[j] = u[j];
            }
        }
        cout << v.front() << "\n";
    }
    return 0;
}

C++: #include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,r,p,c;
	while(cin>>n>>r,n){
		vector<int> d(n),e(n); for(int i=0;i<n;i++)d[i]=n-i;
		for(int i=0;i<r;i++)cin>>p>>c,e=d,copy(d.begin(),d.begin()+p-1,e.begin()+c),
		copy(d.begin()+p-1,d.begin()+p-1+c,e.begin()),d=e;
		cout<<d[0]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main() {
	int n, r;
	while (cin >> n >> r, n || r){
		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;
			stack<int>st1, st2;
			for (int i = 0; i < p - 1; i++) { st1.push(st.top()); st.pop(); }
			for (int i = 0; i < c; i++) { st2.push(st.top()); st.pop(); }
			for (int i = 0; i < p - 1; i++) { st.push(st1.top()); st1.pop(); }
			for (int i = 0; i < c; i++) { st.push(st2.top()); st2.pop(); }
		}
		cout << st.top() << endl;
	}
}