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>
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;
}

C++: #include <stdio.h>

int main(){
    int n,r,i,j,p,c,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]=i; //a[i]????????????i??????????????????????????????????????????
        }
        for (i=0;i<r;i++) {
            scanf("%d %d",&p,&c);
            for (j=1;j<=c;j++) {
                b[j]=a[j];
                a[j]=a[j+p-1];
            }
            if (p-1>c) {
                for (j=c+1;j<p;j++) {
                    b[j]=a[j];
                }
            }
            for (j=1;j<p;j++) {
                a[j+c]=b[j];
            }
        }
        printf("%d\n",a[1]);
        
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        pair<int, int> n; cin >> n.first >> n.second;
        if(n.first == 0 and n.second == 0) return 0;
        else{
            vector<int> Card(n.first);
            int tmp = n.first;
            for(int i = 0; i < n.first; i++){
                Card[i] = tmp;
                tmp--;
            }
            REP(i, n.second){
                pair<int, int> cut; cin >> cut.first >> cut.second;
                vector<int> New(0);
                for(int i = cut.first - 1; i < cut.first + cut.second - 1; i++) New.push_back(Card[i]);
                REP(i, cut.first - 1) New.push_back(Card[i]);
                FOR(i, cut.first + cut.second - 1, n.first) New.push_back(Card[i]);
                REP(i, n.first) Card[i] = New[i];
            }
            cout << Card[0] << endl;
        }
    }
}

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

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

	}
	return 0;
}

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

int main()
{
	int n,r,p,c;
	int x[64],t[64];
	while(cin >> n >> r, n||r)
	{
		for(int i=0; i<n; i++)
		{
			x[i]=n-i;
		}

		while(r--)
		{
			cin >> p >> c;
			for(int i=0; i<p-1; i++)
			{
				t[i] = x[i];
			}
			for(int i=0; i<c; i++)
			{
				x[i] = x[p-1+i];
			}
			for(int i=0; i<p-1; i++)
			{
				x[c+i] = t[i];
			}
		}
		cout << x[0] << endl;

	}
}

C++: 
#include <stdio.h>
int main(){
  int n,r,p,c,i,j,k,nh[51],s[51];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&&r==0) break;

    for(i=n;i>=1;i--){
      nh[n-i+1]=i;
    }
 
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=p;j<=p+c-1;j++){
        s[j]=nh[j];
      }
      for(j=1;j<=c;j++){
	for(k=p-1;k>=1;k--){
          nh[k+1]=nh[k];
	}
      }
    
      for(j=p;j<=p+c-1;j++){
        nh[j-p+1]=s[j];
      }
    }

    printf("%d\n",nh[1]);
  }
    return 0;
}