Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

C++: 
#include <iostream>

using namespace std;

int main()
{
    int yama[51], tmp[51];

    int n, r;
    while (cin >> n >> r, (n || r))
    {
        for (int i = 0; i < n; i++)
        {
            yama[i] = i + 1;
        }

        for (int i = 0; i < r; i++)
        {
            int p, c;
            cin >> p >> c;
            for (int j = 0; j < c; j++)
            {
                tmp[c - 1 - j] = yama[n - p - j];
            }
            for (int j = n - p + 1; j < n; j++)
            {
                yama[j - c] = yama[j];
            }
            for (int j = 0; j < c; j++)
            {
                yama[n - c + j] = tmp[j];
            }
        }

        cout << yama[n - 1] << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cctype>

using namespace std;

#define REP(i,n) for(int i = 0;i < n;i++)
	
int main()
{
	int n,r;
	while(cin >> n >> r,n)
	{
		vector<int> v;
		REP(i,n)
		{
			v.push_back(i+1);
		}
		REP(i,r)
		{
			int p,c;
			cin >> p >> c;
			vector<int> tmp;
			REP(j,c)
			{
				tmp.push_back(v[v.size()-p-j]);
			}
			v.erase(v.end()-p-c+1,v.end()-p+1);
			REP(j,c)
			{
				v.push_back(tmp[tmp.size()-j-1]);
			}
		}
		
		cout << v.back() << endl;
		
	}
	
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int main(){
    int n,r;
    while(cin >> n >> r,n) {
        vi card(n);
        rep(i,n) card[i] = n - i;
        rep(i,r){
            int p,c;
            cin >> p >> c;
            vi tmp(c);
            rep(j,c) tmp[j] = card[p - 1 + j];
            rrep(j,p - 1) card[j + c - 1] = card[j];
            rep(j,c) card[j] = tmp[j];
        }
        cout << card[0] << endl;
    }
    return 0;

}

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

using namespace std;

int main() {
  int n, r;
  cin >> n >> r;

  if (!n) return 0;

  vector<int> ary;
  for (int i = n; i >= 1; i--) {
    ary.push_back(i);
  }
  for (int i = 0; i < r; i++) {
    vector<int> tmp;
    int p, c;
    cin >> p >> c;
    for (int j = 0; j < c; j++) {
      tmp.push_back(ary[p - 1 + j]);
    }
    for (int j = p - 2; j >= 0; j--) {
      ary[j + c] = ary[j];
    }
    ary = tmp;
    tmp.clear();
  }
  cout << ary[0] << endl;

  main(); // kikaku ihan dakedo
}

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


using namespace std;
int main()
{
    int n,r;
    while(cin>>n>r){
        
        if(n==0&&r==0)break;
        stack<int> st1;
        for(int i=0; i<n; i++){
            st1.push(i+1);
        }
        
        for(int rop=0; rop<r; rop++){
            int p,c;
            cin>>p>>c;
            stack<int> st2,st3;
            for(int i=0; i<p-1; i++){
                st2.push(st1.top());
                st1.pop();
            }
            
            for(int i=0; i<c; i++){
                st3.push(st1.top());
                st1.pop();
            }
            
            while (!st2.empty()) {
                st1.push(st2.top());
                st2.pop();
            }
            
            while (!st3.empty()) {
                st1.push(st3.top());
                st3.pop();
            }
        }
        
        cout<<st1.top()<<endl;
    }
}

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

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


int main(int argc, const char * argv[])
{
    int n, r;
    while(cin >> n >> r){
        if(n == 0 || r == 0) return 0;
        
        int cards[n];
        int next[n];
        
        for(int i = 0; i < n; i++){
            cards[i] = i;
        }
        
        int p, c;
        for(int i = 0; i < r; i++){
            cin >> p >> c;
            int j = 0;
            for(j = 0; j < c; j++){
                next[j] = cards[p+j];
            }
            for(int k = 0; k < p; k++){
                next[j] = cards[k];
                j++;
            }
            for(;j < n; j++){
                next[j] = cards[j];
            }
            
            for(int j = 0; j < n; j++){
                cards[j] = next[j];
            }
        }
        
        cout << cards[0] << "\n";
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																

	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long L;
vector<L>v;
L n,r,x,y;
void init(L n){
    v.clear();
    for(L i=0;i<n;i++){
        v.push_back(i+1);
    }
}
void shuffle_(L x,L y){
    L s,e,c=0;
    if(x==1&&y==n)return;
    e=n-x;s=n-(x+y-1);
    c=e-s+1;/// 1 2 3 4 5
    while(c--){
        L d=v[s];
        v.erase(v.begin()+s);
        v.push_back(d);
    }
}
int main(){
    while(scanf("%lld%lld",&n,&r)){
        if(n==0&&r==0)return 0;
        init(n);
        for(L i=0;i<r;i++){
            scanf("%lld%lld",&x,&y);
            shuffle_(x,y);
        }
        cout<<v[n-1]<<"\n";
    }
    return 0;
}

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

int main()
{
	while (true)
	{
		int n, r;
		scanf("%d%d", &n, &r);
		if (n == 0 && r == 0) break;
		std::vector<int> cards(n);
		for (int i{}; i < n; i++) cards[i] = i + 1;

		for (int r_i{}; r_i < r; r_i++)
		{
			int p, c;
			scanf("%d%d", &p, &c);
			for (int c_i{}; c_i < c; c_i++)
				for (int p_i{n - p - c_i}; p_i < n - 1 - c_i; p_i++)
					std::swap(cards[p_i], cards[p_i + 1]);
		}
		printf("%d\n", cards.back());
	}

	return 0;
}