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 ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}


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

signed main()
{
	IOS();
	int N,M;
	vector<int>ans;
	while(1){
		cin>>N>>M;
		if(N==0&&M==0)break;
		vector<int>a(N);
		rep(i,0,N)a[i]=N-i-1;
		rep(i,0,M){
			int P,C;
			cin>>P>>C;
			P--;
			vector<int>tmp;
			rep(j,P,P+C){
				tmp.push_back(a[j]);
			}
			rep(j,0,P){
				tmp.push_back(a[j]);
			}
			rep(j,0,tmp.size())a[j] = tmp[j];
		}
		ans.push_back(a[0]);
	}
	for(auto e:ans)cout<<e+1<<endl;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;


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


	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;


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


	return 0;
}

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

using namespace std;

int main(void)
{
	int n, r;
	while(cin >> n >> r && n!=0 && r != 0)
	{	
		vector<int> A(n);
		for(int i = 0;i < n; i++)
		{
			A[i] = n - i;
		}

		int p, c;

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

			if(c != A.size() && ( (p + c - 1) != n ) )
			{
				rotate(A.begin(), A.begin() + A.size() - p, A.begin() + A.size() - p + c);
			}
			else if( (p + c -1) == A.size() )
			{
				for(int i = 1; i <= n - c; i++)
				{
					rotate( A.begin(), A.begin() + 1, A.end());
				}
			}

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

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

using namespace std;
int main(){
  int n,r;
  int p,c;
  cin >> n >> r;

  while(n != 0 || r != 0){
    vector<int> card(51,0);
    vector<int>::iterator it;
    it = card.begin();
    for(int i = 0; i < n ; i++){
      card[i] = n-i;
    }
    for(int i = 0 ; i < r;i++){
      cin >> p >> c;
      vector<int> have(c,0);
      have.assign(it+p-1,it+p+c-1);
      card.erase(it+p-1,it+p+c-1);
      card.insert(it,have.begin(),have.end());
    }
    cout << card.at(0) << endl;
    cin >> n>> r;
  }

  return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, r; cin >> n >> r, n;){
        string yama;
        rep(i, n){
            char c = (n - i) + '0';
            yama.push_back(c);
        }
        
        while(r --){
            int p, c; cin >> p >> c;
            
            string str = yama.substr(p - 1, c);
            yama.replace(p - 1, c, "");
            yama = str + yama;
        }
        cout << yama[0] - '0' << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(i) i.begin(),i.end()

using namespace std;
	
vector<int> doCut(int p,int c,vector<int> x,int n){
	vector<int> ret;
	for(int i=p-1;i<=p-1+c-1;i++){
		ret.push_back(x[i]);
	}
	rep(i,p-1){
		ret.push_back(x[i]);
	}
	for(int i=p+c-1;i<=n-1;i++){
		ret.push_back(x[i]);
	}
	return ret;
}

int main(){
	int n,r;
	while(1){
		vector<int> x;
		cin>>n>>r;

		for(int i=n-1;i>=0;i--){
			x.push_back(i+1);
		}
		if(n==0 && r==0)break;

		rep(i,r){
			int p,c;
			cin>>p>>c;
			x=doCut(p,c,x,n);

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

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

int main(){
	int n,r,p[100],c[100],hanafuda[100][100],b;
	while(true){
		cin>>n>>r;
		if(n==0 && r==0){
			break;
		}
		for(int i=1;i<=n;i++){
			hanafuda[i][0]=n-i+1;
		}
		for(int i=1;i<=r;i++){
			
			b=0;
			cin>>p[i]>>c[i];

			for(int j=p[i];j<p[i]+c[i];j++){
				b++;
				hanafuda[b][i]=hanafuda[j][i-1];
			}
			for(int j=1;j<p[i];j++){
				b++;
				hanafuda[b][i]=hanafuda[j][i-1];
			}
			for(int j=p[i]+c[i];j<=n;j++){
				b++;
				hanafuda[b][i]=hanafuda[j][i-1];
			}
		}
		cout<<hanafuda[1][r]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, r;

	while (scanf("%d %d", &n, &r), n){
		vector<int> v;

		for (int i = 0; i < n; i++){
			v.push_back(n - i);
		}

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

			scanf("%d %d", &p, &c);

			stack<int> s;

			for (int j = p - 1; j < p + c - 1; j++){
				s.push(v[j]);
				v[j] = 0;
			}

			for (int j = n - 1; j > c; j--){
				if (v[j] == 0){
					v[j] ^= v[j - c];
					v[j - c] ^= v[j];
					v[j] ^= v[j - c];
				}
			}

			for (int j = c - 1; j >= 0; j--){
				v[j] = s.top();
				s.pop();
			}
		}

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

	return (0);
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
  int i, j;
  while (1) {
    int n, r;
    scanf("%d %d", &n, &r);
    if (n == 0) break;
    vector<int> a(n); // int a[n]
    for (i = 0; i < n; i++) {
      a[i] = n-i;
    }
    for (i = 0; i < r; i++) {
      int p, c;
      scanf("%d %d", &p, &c);
      auto x = vector<int>(a.begin(), a.begin() + p - 1);
      auto y = vector<int>(a.begin() + p - 1, a.begin() + p - 1 + c);
      auto z = vector<int>(a.begin() + p - 1 + c, a.end());
      a = y;
      copy(x.begin(), x.end(), back_inserter(a));
      copy(z.begin(), z.end(), back_inserter(a));
    }
    cout << a.front() << endl;
  }
}