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 <bits/stdc++.h>

using namespace std;


int main(){

  int n,r,p,c;
  vector<int> y,P,C;

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

    y.clear();
    y.resize(n);
    for(int i=0; i<y.size(); ++i){
      y[i]=i+1;
    }
    
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      
      P.clear();
      P.resize(y.size()-p);
      C.clear();
      C.resize(c);
      
      for(int k=0; k<P.size(); ++k){
	P[k]=y[k+p];
      }
      
      for(int k=0; k<C.size(); ++k){
	C[k]=y[k+p-c];
      }

      for(int k=0; k<P.size(); ++k){
	y[k+p-c]=P[k];
      }
      
      for(int k=0; k<C.size(); ++k){
	y[y.size()-c]=C[k];
      }

 
    }

    cout << y[y.size()-1] << endl;
  }

  
  return 0;
}

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

int main(void){
int n,r;
int p,c;
while(true){
cin>>n>>r;
if(n==0&&r==0)return 0;
vector<int> ca(n);
vector<int> t(n,0);
vector<int> t2(n,0);
for(int i=0;i<n;i++)ca[i]=n-i;
for(int i=0;i<r;i++){
	cin>>p>>c;
	for(int j=0;j<c;j++){
		t[p-1+j]=ca[p-1+j];
	}
	for(int k=0;k<p-1;k++){
		t2[c+k]=ca[k];
	}
	for(int k=0;k<p-1;k++){
		ca[c+k]=t2[c+k];	
	}
	for(int j=0;j<c;j++){
		ca[j]=t[p-1+j];
	}
}
cout<<ca[0]<<endl;
}
return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
using namespace std;

typedef vector<int> Ivec;

int main() {
	int n, r;

	while (scanf("%d %d", &n, &r)) {
		if (n == 0) 
			return 0;

		Ivec fuda;
		for (int i = n; 0 < i; i--)
			fuda.push_back(i);

		int p, c;
		for (int i = 0; r > i; i++) {
			scanf("%d %d", &p, &c);
			Ivec buf(fuda);
			for (int j = 0; c > j; j++) {
				fuda.insert(fuda.begin()+j, buf[p-1+j]);
			}
		}
		printf("%d\n", fuda[0]);
	}
	return 0;
}

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

int erase_alt(list<int> &lis, list<int>::iterator itr)
{
	int temp = *itr;
	lis.erase(itr);
	return temp;
}

int main()
{
	while (true)
	{
		list<int> list0;
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		for (int i=n; i > 0; i--)
		{
			list0.push_back(i);
		}
		for (int i = 0; i<r; i++)
		{
			int p, c;
			list<int>::iterator itr = list0.begin();
			cin >> p >> c;
			if (p == 1)continue;
			advance(itr, p - 1);
			list0.splice(list0.begin(), list0, itr, next(itr, c));
		}
		cout << *list0.begin() << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void){
	int p, c, count, n, r, huda[200] = {0}, i, j,an[100],a=0;
	while (1) {
		scanf("%d %d", &n, &r);
		for (i = 0;i < n;i++) {
			huda[i] = i + 1;
		}
		if (n == 0 && r == 0) {
			break;
		}
		for (i = 0;i < r;i++) {
			scanf("%d %d", &p, &c);

			for (j = 0;j < c;j++) {
				huda[n + j] = huda[n - p];
				huda[n - p] = -1;
			}

			count = 0;
			for (j = 0;j < n;j++) {

				if (count > n)
					break;
				huda[j] = huda[count];
				if (huda[count] == -1) {
					j--;
				}
				count++;

			}

		}
		an[a] = huda[n - 1];
		a++;
	}
	for (i = 0;i < a;i++) {
		printf("%d\n", an[i]);
	}

	return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,r;
	
	while(cin >> n >> r , n){
		int card[n],t[n];
		rep(i,n)card[n-i-1]=i+1;

		rep(i,r){
			rep(j,n)t[j] = card[j];
			int p,c;
			cin >> p >> c;
			rep(j,c)t[j] = card[p-1+j];
			rep(j,p)t[c+j] = card[j];
			rep(j,n)card[j] = t[j];
		}
		cout << card[0] << endl;
	}
}

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

int main()
{
	while (true) {
		int n, r;
		int cards[50];

		cin >> n >> r;

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

		for (int i = 0; i < 50; i++) {
			int temp = max(0, n - i);
			cards[i] = temp;
		}

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

			cin >> p >> c;

			vector<int> shuffle;

			for (int j = 0; j < c; j++) {
				shuffle.push_back(cards[p - 1 + j]);
			}

			for (int j = p - 2; j >= 0; j--) {
				cards[c + j] = cards[j];
			}
			
			for (int j = 0; j < c; j++) {
				cards[j] = shuffle[j];
			}
		}

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

	return 0;
}

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

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r,c,p;
    vector<int> s,s2;
    cin >> n >> r;
    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 << s[i] << "  ";
        }
        cout << endl;
        s2.clear();
    }
    cout << s[n-1] << "\n";
}

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

int main() {
  
  while(1){
    
    int n,r,i,j,k;
    cin >>n>>r;
    if (n==0&&r==0)break;
    
    vector<int> nom;
    for(i=0;i<n;i++)
      nom.push_back(n-i);
    
    for(i=0;i<r;i++){
      int p,c;
      cin >>p>>c;
      for(j=0;j<p-1;j++){
	int temp;
	temp = nom[0];
	for(k=0;k<p+c-2;k++)nom[k]=nom[k+1];
	nom[c+p-2] = temp;
      }
    }
    cout << nom[0] <<endl;
    
  }
  return 0;
  
}

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

int main(){
  int n, r;
  while((cin >> n >> r), n,r){
    string s="",t="",u="", v="";
    for(int i=n; i>=1; i--){
      s+=i+'0';
    }
    for(int i=0; i<r; i++){
      int x, y;
      cin >> x >> y;
      t = s.substr(x-1,y);
      u = s.substr(x+y-1,s.length());
      v = s.substr(0,x);
      s = t+v+u;
    }
    int pp = s[0]-'0';
    cout << pp << endl;
  }

  return 0;
}