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>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++)
		after[i]=tmp[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	if((n==0) && (r==0))
		return false;
	for(i=0;i<n;i++)
		before[i]=n-i;	
	return true;
}

void Shuffle(int b[], int a[], int t[]){
	int j;
	for(j=0;j<c;j++){
		a[j]=b[p-1+j];
		t[j]=b[p-1+j];
	}
	for(j=0;j<p-1;j++){
		a[c+j]=b[j];
		t[c+j]=b[j];
	}
	for(j=0;j<n;j++)
		b[j]=t[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after,tmp);
	}
	return after[0];
}


int main(){
  while(init(),input()){
	cout<<solve()<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
        int n,r;
        cin >> n >> r; 
        while(n){
                int in[50][2];
                for(int i = 0; i < r; i++){
                        cin >> in[i][0] >> in[i][1];
                }  
                int m = n; 
                for(int i = r-1; i >= 0; i--){
                        int p = in[i][0];
                        int c = in[i][1];
                        if(n-(p-1)-c >= m) continue;
                        if(n-c < m){
                                m -= p-1;
                        }else{
                                m += c; 
                        }  
                }  
                cout << m << endl;
                cin >> n >> r; 
        }  
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define Reps(i, x, N) for(int i = x; i < N; i++)

const int LLINF = 1LL << 60;


signed main()
{
  int N, R;

  while(cin >> N >> R, N || R) {
    int p, c;
    
    int num[55];
    Rep(i, N) num[i] = N - i - 1;
    
    while(R--) {
      int temp[55];

      cin >> p >> c; --p;
      
      Rep(i, c) temp[i] = num[i + p];
      for(int i = p - 1; i >= 0; i--) num[c + i] = num[i];
      Rep(i, c) num[i] = temp[i];
    }
    cout << num[0] + 1 << endl;
  }

  return 0;
}

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

int main() {
    while(true) {
        int nCard, cycle; cin >> nCard >> cycle;
        if(nCard == 0 && cycle == 0) return 0;
        vector<int> card(nCard);
        for(int i = 0; i < nCard; i++) card[i] = i+1;
        reverse(card.begin(), card.end());

        for(int i = 0; i < cycle; i++) {
            int loc, num; cin >> loc >> num;
            rotate(card.begin(), card.begin()+loc-1, card.begin()+loc-1+num);
        }
        cout << card[0] << endl;
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>

using namespace std;

int main(){

	int n,r,table[50],p,c,work[50];

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

		for(int i = 0; i < n; i++){
			table[i] = n-i;
		}

		for(int i = 0; i < r; i++){
			scanf("%d %d",&p,&c);

			//???????????????????????£???????????????????????????
			for(int k = 0; k < c; k++){
				work[k] = table[p-1+k];
			}

			//?¬???????0???p-2?????§????????????
			for(int k = 0; k < p-1; k++){
				work[c+k] = table[k];
			}

			//????????????p+c-1???n-1?????§????????????
			for(int k = p+c-1; k < n; k++){
				work[k] = table[k];
			}

			for(int k = 0; k < n; k++)table[k] = work[k];
		}

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

	}

    return 0;
}

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

int main(){

    while(1){
        int n, r;
        cin >> n >> r;
        if(n == 0){
            break;
        }

        vector<int> now(n);
        vector<int> next(n);

        for(int i = 0; i < n; i++){
            now[i] = n - i;
        }

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

            for(int j = c + p - 1; j < n; j++){
                next[j] = now[j];
            }

            swap(now, next);
        }

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

    return 0;
}

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

using namespace std;

int main(){
    int n,r,p,c,a[50];

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

        for(int i=0;i<r;i++){
            cin >> p >> c;
            rotate(a,a+p-1,a+p+c-1);
        }
    cout << a[0] << endl;
    }

    return 0;

}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[50]={0};
	int mem[50]={0};
	int n;
	int r;
	int k = 0 ;
	int p,c;
	while(1){
		cin >>n >>r;
		if ((n==0)&&(r==0)) break;
		for(int i =0;i<n;i++){
			card[i]=i+1;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[l];
			}
			for(int m=0;m<p-1;m++){
				card[n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int o=0;o<c;o++){
				card[n-c+o]=mem[n-p-c+1+o];
			}
		}
		cout << card[n-1] <<endl;
		

	}
	
	return 0;
}

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

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

int main(void){
    while(true){
        int n=0, r=0, yama[55], tmp[55];
        cin >> n >> r;
        if(n==0 && r==0) break;
        for(int i=0;i<n;++i) yama[i] = n-i;
        for(int i=0;i<r;++i){
            int p, c;
            cin >> p >> c;
            for(int j=0;j<p-1;++j) tmp[j] = yama[j];
            for(int j=0;j<c;++j) yama[j] = yama[p-1+j];
            for(int j=0;j<p-1;++j) yama[c+j] = tmp[j];
        }
        cout << yama[0] << endl;
    }
}

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

int main()
{
	int n, r;
	while (cin >> n >> r, n + r)
	{
		deque<int> ary;
		for (int i = 1; i <= n; i++) ary.push_front(i);

		while (r--)
		{
			int p, c;
			cin >> p >> c;
			int i = p + c - 2;
			while (c--)
			{
				int tmp = ary[i];
				ary.erase(ary.begin() + i);
				ary.push_front(tmp);
			}
		}

		cout << ary.front() << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std; 
int main()
{
  int n, cut;
  int A[50],B[50],i,j,p,c;
  while(1){
      cin>>n>>cut;
      if(n==0&&cut==0)break;
      else{
      for(i=0; i<=n-1; i++)A[i]=n-i;
      while(cut--){
          cin>>p>>c;
          for(j=0; j<n; j++)B[j]=A[j];
          for(j=0; j<p-1; j++)B[j+c]=A[j];
          for(j=0; j<c;j++)B[j]=A[j+p-1];
          for(j=0; j<n;j++)A[j]=B[j]; 
        }}
      cout<<A[0]<<endl;}
      return 0;
    }

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

int main() {
	vector<int> d;
	int n, r, p, c, tmp;
	cin >> n >> r;
	while(n != 0) {
		d.resize(n);
		for (int i = 0;i < n;i ++) d[i] = i + 1;
		for (int i = 0;i < r;i ++) {
			cin >> p >> c;
			for (int j = 0;j < c;j ++) {
				tmp = d[n - p - c + 1];
				d.erase(d.begin() + n - p - c + 1);
				d.push_back(tmp);
			}
		}
		cout << d[n - 1];
		cin >> n >> r;
		cout << endl;
	}
	return 0;
}