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

int N, R;
int S[50];

int main() {
  while (cin >> N >> R) {
    if (N == 0 && R == 0) break;
    for (int i=0; i<N; i++) S[i] = N-i;
    for (int i=0; i<R; i++) {
      int p, c;
      cin >> p >> c;
      vector<int> t;
      for (int i=p-1; i<p+c-1; i++) t.push_back(S[i]);
      for (int i=p-2; i>=0; i--) {
        S[i+c] = S[i];
      }
      for (int i=0; i<c; i++) S[i] = t[i];
    }
    cout << S[0] << "\n";
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r,c,p;
    vector<int> s,s2;
    while(1){
        cin >> n >> r;
        if(n==0&&r==0)  break;
        for(int i=1;i<=n;i++){
            s.push_back(i);
        }
        while(r--){
            cin >> p >> c;
            for(int i=0;i<n-c-p+1;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-p+1;i<n;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-c-p+1;i<n-p+1;i++){
                s2.push_back(s[i]);
            }
            s.clear();
            for(int i=0;i<n;i++){
                s.push_back(s2[i]);
            }
            cout << endl;
            s2.clear();
        }
        cout << s[n-1] << "\n";
        s.clear();
    }
}

C++: #include<iostream>
using namespace std;
int main(){

    int n,r;
    while(cin>>n>>r,n){
        int a[2][60];
        int now = 1;
        for(int i = 0;i < n;i++)a[0][i] = i;
        while(r--){
            int p,c;
            cin>>p>>c;
            p--;
            for(int i = p;i < p+c;i++){
                a[now][i-p] = a[1-now][i];
            }
            for(int i = 0,t = 0;i < n;i++){
                if(p<=i&&i<p+c)continue;
                a[now][t+c] = a[1-now][i];
                t++;
            }
            //for(int i = 0;i < n;i++)cout<<a[now][i]<<" ";
            //cout<<endl;
            now = 1-now;
        }
        cout<<n-1-a[1-now][0]+1<<endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    while(1){
        int n,r,num[51],p,c;
        cin >> n >> r;
        if(n==0&&r==0)  break;
        for(int i=1;i<=n;i++) num[i] = i;   
        for(int i=0;i<r;i++){
            cin >> p >> c;
            for(int j=p,x=n;j>=p-c;j--,x--){
                swap(num[j],num[x]);
            }
        }
        cout << num[n]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
	int n,r;
	while(cin>>n>>r,n) 
	{
		string deck="";
		for(int i = n; 0 < i; --i)
		{
			deck+='0'+i;
		}

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

			string t="",m="",b="";
			t=deck.substr(0,p-1);
			m=deck.substr(p-1,c);
			b=deck.substr(p-1+c);

			deck=m+t+b;
		}
		cout<<deck[0]<<endl;
	}
  return 0;
}

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

typedef stack<int> S;

int main(void)
{
	int n, r;
	while (cin >> n >> r && n && r) {
		S s, s1, s2;
		int p, c;
		for (int i = 1; i < n+1; i++) s.push(i);
		for (int j = 0; j < r; j++) {
			cin >> p >> c;
			for (int i = 0; i < p-1; i++) {
				s1.push(s.top());
				s.pop();
			}
			for (int i = 0; i < c; i++) {
				s2.push(s.top());
				s.pop();
			}
			for (int i = 0; i < p-1; i++) {
				s.push(s1.top());
				s1.pop();
			}
			for (int i = 0; i < c; i++) {
				s.push(s2.top());
				s2.pop();
			}
		}
		cout << s.top() << endl;
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,r,p,c,i,j,a[51],b[51];
	while(1)	{
		scanf("%d %d",&n,&r);
		if(n==0 && r==0)	break;
		for(i=1;i<=n;i++)	{
			a[i]=n-i+1;
		}
		for(j=0;j<r;j++)	{
		
		//	for(i=1;i<=n;i++)	printf(" %d\n",a[i]);
		
			scanf("%d %d",&p,&c);
			for(i=1;i<=c;i++)	{
				b[i]=a[i+p-1];
			}
			for(i=c+1;i<c+p;i++)	{
				b[i]=a[i-c];
			}
			for(i=c+p;i<=n;i++)	{
				b[i]=a[i];
			}
			for(i=1;i<=n;i++)	{
				a[i]=b[i];
			}
		}
		printf("%d\n",a[1]);
	}
	return 0;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int n, r;
vector<int> p, c;
void ops(vector<int> &card, int p, int c) {
    auto tmp = card;
    p--;
    rep(i, p) {
        card[i + c] = tmp[i];
    }
    rep(i, c) {
        card[i] = tmp[i + p];
    }
}
void solve() {
    vector<int> card(n);
    rep(i, n) card[i] = n - i;
    rep(i, n) cout << card[i] << " ";
    cout << endl;
    rep(i, r) {
        ops(card, p[i], c[i]);
        // rep(i, n) cout << card[i] << " ";
        // cout << endl;
    }
    cout << card[0] << endl;
}
int main() {
    while (cin >> n >> r, n) {
        p.resize(r);
        c.resize(r);
        rep(i, r) cin >> p[i] >> c[i];
        solve();
    }

    return 0;
}

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

int main() {
	int n, r;
	while( cin >> n >> r, n&&r ) {
		vector<int>N( n ), M, L;
		iota( N.begin(), N.end(), 1 );
		for( size_t i = 0; i < r; i++ ) {
			int a, b;
			cin >> a >> b;
			a--;
			for( size_t j = 0; j < a; j++ ) {
				M.push_back( *N.rbegin() );
				N.pop_back();
			}
			for( size_t j = 0; j < b; j++ ) {
				L.push_back( *N.rbegin() );
				N.pop_back();
			}
			for( size_t j = 0; j < a; j++ ) {
				N.push_back( *M.rbegin() );
				M.pop_back();
			}
			for( size_t j = 0; j < b; j++ ) {
				N.push_back( *L.rbegin() );
				L.pop_back();
			}
		}
		cout << *N.rbegin() << endl;
	}
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main()
{
	while (true)
	{
		int n, r;
		cin >> n >> r;
		if (!n && !r)
			break;
		stack<int> S;
		stack<int> s1;
		stack<int> s2;
		for (int i = 1; i <= n; i++)
			S.push(i);
		for (int i = 1; i <= r; i++)
		{
			int p, c;
			cin >> p >> c;
			for (int i = 1; i <= p - 1; i++)
			{
				int t = S.top();
				S.pop();
				s1.push(t);
			}
			for (int i = 1; i <= c; i++)
			{
				int t = S.top();
				S.pop();
				s2.push(t);
			}
			for (int i = 1; i <= p - 1; i++)
			{
				int t = s1.top();
				s1.pop();
				S.push(t);
			}
			for (int i = 1; i <= c; i++)
			{
				int t = s2.top();
				s2.pop();
				S.push(t);
			}
		}
		cout << S.top() << endl;
	}
}