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 <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, r, p, c, i, ans;
	
	while (cin >> n  && cin >> r) {
		int Deck[51];

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

		for (i = 0; i < n; i++) {
			Deck[i] = n-i;
		}

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

			rotate(Deck, Deck + p - 1, Deck + p + c - 1);
		}

		cout << Deck[0] << endl;
	}
}

C++: #include <iostream>

using namespace std;

int n, r, p, c;
int cards[50];
int temp[50];

int main()
{
	while( 1 )
	{
		cin >> n >> r;
		if(n==0 && r==0) break;
		
		for(int i=0; i<n; i++) cards[i] = n-i-1;
		for(int i=0; i<r; i++)
		{
			cin >> p >> c;
			memcpy(&temp[0], &cards[p-1], sizeof(int) * c);
			memcpy(&temp[c], &cards[0], sizeof(int) * (p-1));
			for(int j=0; j<p+c-1; j++) cards[j] = temp[j];
		}
		printf("%d\n", cards[0]+1);
   	}
}

C++: #include <iostream>
#include <limits.h>
#include <vector>
#include <algorithm>

#define el endl
#define fd fixed

using namespace std;

int main() {
  int n, r, p, c;
  while (cin >> n >> r, n+r) {
    vector<int> yama;
    for (int i = n; i > 0; i--) yama.push_back(i);
    while (r--) {
      cin >> p >> c;
      rotate(yama.begin(), yama.begin()+p-1, yama.begin()+p-1+c);
    }
    cout << yama[0] << el;
  }
}

C++: //#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
//#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

int main(void){

	int n, r;
	// char ;

	while (scanf("%d %d", &n, &r) != EOF){
		if (n == 0 && r == 0) break;
		int card[100];
		for (int j = 1; j <= n; j++){
			card[j] = n - j + 1;
		}

		for (int i = 0; i < r; i++){
			int p, c;
			int buff[100];
			scanf("%d %d", &p, &c);

			for (int j = 0; j < c; j++){
				buff[j] = card[p + j];
			}

			for (int j = p + c - 1; j >= c + 1; j--){
				card[j] = card[j - c];
			}

			for (int j = 0; j < c; j++){
				card[j + 1] = buff[j];
			}

		}
		
		cout << card[1] << endl;

	}

	return 0;
}

/*
for(i=0;i<N;i++){
cin >> X[i];
}


for(i=0;i<N;i++){
for(j=0;j<N;j++){
cin >> X[i][j];
}
}
*/

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

typedef long long ll;
typedef pair<int,int> P;

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int n, r ; cin >> n >> r, n || r; ) {
		vector<int> v(n);
		rep(i,n) v[i] = n - i;
		rep(i,r) {
			int p, c;
			vector<int> tmp;
			cin >> p >> c;
			rep(j,c) {
				tmp.pb(v[p+j - 1]);
			}
			rep(j,p - 1) {
				tmp.pb(v[j]);
			}
			for(int j = p + c - 1; j < n; j++) {
				tmp.pb(v[j]);
			}
#if 0
			preview(tmp.begin(), tmp.end());
#endif
			v = tmp;
		}
		cout << *v.begin() << endl;
	}
	return 0;
}

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

using namespace std;
int n, r, p, c;

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

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

int main(){
	int n, r, p, c;
	const int SIZE = 50;
	int card[SIZE];
	int P[SIZE], C[SIZE];
	
	while(true){
		scanf("%d%d", &n, &r);
		if(n == 0 && r == 0) break;
		
		for(int i = n; i > 0; i--){
			card[n - i] = i;
		}
		
		for(int i = 0; i < r; i++){
			scanf("%d%d", &p, &c);
			for(int j = 0; j < p - 1; j++) P[j] = card[j];
			for(int j = 0; j < c; j++) C[j] = card[j + p - 1];
			
			for(int j = 0; j < c; j++) card[j] = C[j];
			for(int j = 0; j < p - 1; j++) card[j + c] = P[j];
		}
		
		printf("%d\n", card[0]);
	}
	
	return 0;
}

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

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

	while(true){
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}

		int* cards = new int[n];
		for(int i=0;i<n;i++){
			cards[i] = n-i;
		}
		int* buf = new int[n];
		for(int i=0;i<r;i++){
			cin >> p >> c;
			for(int j=0;j<c;j++){
				buf[j] = cards[p+j-1];
			}
			int count = c;
			for(int j=0;j<n;j++){
				if(j<p-1 || p-1+c < j){
					buf[count] = cards[j];
					count++;
				}
			}

			for(int j=0;j<n;j++){
				cards[j] = buf[j];
			}
		}

		cout << cards[0] << endl;
	}
}

C++: /*Hanafuda Shuffle*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;

int main(void){
  int d=0;
  int n,r,p,c;
  while(d==0){
    cin >> n >> r;
    if(n==0 && r==0)break;
    vector<int> a(n,0);
    for(int i=0;i<n;i++){
      a[i]=i+1;
    }
    reverse(a.begin(),a.end());
    for(int i=0;i<r;i++){
      cin >> p >> c;
      rotate(a.begin(),a.begin()+p-1,a.begin()+p-1+c);
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
int n,r;
int f[55],cp[55];
int main(void){
	for(;;){
		scanf("%d%d",&n,&r);
		if(n==0)break;
		rep(i,0,n)f[i]=n-i;
		rep(i,0,r){
			int a,b;
			scanf("%d%d",&a,&b);
			memcpy(cp,f,(a-1)*4);
			memcpy(f,f+a-1,b*4);
			memcpy(f+b,cp,(a-1)*4);
		}
		printf("%d\n",f[0]);
	}
	return 0;
}