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

int main(){
  int n, r;
  while(cin >> n >> r && n){
    // cout << "n" << n << "r" << r <<endl;
    // ?±±?????????
    vector<int> fuda(n,0);
    for(size_t i=0; i<fuda.size(); i++) fuda[fuda.size()-1-i] = i+1;
    for(int i=0; i<r ; i++){
      int p, c;
      cin >> p >> c;
      // ?????£???????????????
      rotate(fuda.begin(),fuda.begin()+(p-1),fuda.begin()+(p-1)+c);  
      // for(size_t j=0 ; j<fuda.size(); j++) cout << fuda[j] << " ";
      // cout << endl;
    }
    cout << fuda[0] << endl;
  }
}

C++: #include<stdio.h>
 
int main(void)  {
    int n,r,p,c;
 
    while(1)    {
        scanf("%d %d", &n, &r);
        if(n == 0) break;
 
        int card[n];
        int temp[n];
        for(int i = 0;i <= n - 1;i++)   card[i] = n - i;
 
        for(int i = 0;i <= r - 1;i++)   {
            scanf("%d %d", &p, &c);
 
            int count = 0;
            for(int i = p - 1;i <= p + c - 2;i++)   {
                temp[count] = card[i];
                count++;
            }

            for(int i = 0;i <= p - 2;i++)   {
                temp[count] = card[i];
                count++;
            }
 
            for(int i = p + c - 1;i <= n - 1;i++)   {
                temp[count] = card[i];
                count++;
            }

            for(int i = 0;i <= n - 1;i++)   {
                card[i] = temp[i];
            }
        }
 
        printf("%d\n", card[0]);
    }
     
    return 0;
}

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

int main(void)
{
	while ( true ) {
		std::vector<int> yama;
		int n, r;

		std::cin >> n;
		std::cin >> r;

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

		yama.resize(n);

		for ( int i = 0; i < n; ++i ) {
			yama[i] = i + 1;
		}

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

			int b = n - p;

			std::vector<int> d(c);

			for ( int j = 0; j < c; ++j ) {
				d[c - j -1] = yama[b - j];
			}

			for ( int j = b; j < n; ++j ) {
				yama[j - c] = yama[j];
			}

			for ( int j = n - c; j < n; ++j ) {
				yama[j] = d[j - n + c];
			}
		}

		std::cout << yama[n - 1] << std::endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	int n, r;
	vector<int> card;
	while(true){
		cin >> n >> r;
		if(!n && !r) break;
		card.clear();
		// 1 .. n
		for(int i = 1; i <=n ; i++){
			card.push_back(i);
		}

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

			cin >> p >> c;
			if(n == c) continue;
			
			vector<int>::iterator it = card.end() - p - c + 1;
			
			// temp
			for(int j = 0; j < c; j++){
				card.push_back(*it);
				it++;
			}
			//erase
			card.erase(it  - c, it);
		}
		cout << card[n-1] << endl;
	}
	return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	while (1) {
		int n, r;
		int p, c;
		int a[51] = {};
		int b[51] = {};
		
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}
		FOR(i, 1, n) {
			a[i] = n - i + 1;
		}
		FOR(i, 1, r) {
			cin >> p >> c;
			FOR(t, 1, p - 1) {
				b[t] = a[t];
			}
			FOR(t, 1, c) {
				a[t] = a[p + t - 1];
			}
			FOR(t, 1, p - 1) {
				a[c+t] = b[t];
			}
		}
		cout << a[1] << endl;
	}

}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
using namespace std;

int main()
{
  int n,r;
  int i,j,k;
  int p,c;
  int a[60];//a[0]??????
  int b[60];
  int x;

  while(1){
    cin>>n>>r;
    if(n==0 && r==0)break;
    puts("");
    for(i=0;i<n;i++)
      a[i]=n-i;

    for(i=0;i<r;i++){
      cin>>p>>c;
      for(j=0;j<c;j++)//c??????????????????
	b[j]=a[p-1+j];
      for(k=0;k<p-1;k++)//p-1???????????¨???
	b[j+k]=a[k];
      for(x=0;x<j+k;x++)//??????????????????
	a[x]=b[x];      
    }    
    cout<<a[0]<<endl;
  }
}

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

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

C++: #include<stdio.h>
int main()
{
  int j,i,n,p,c,r,ss=0;
  int N[100000],C[10000],X[10000];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0 && r==0)break;
    for(i=0;i<n;i++){
      N[i]=i+1;
    }
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=0;j<c;j++){
	C[j]=N[n-p-j];
      }
      for(j=n-p+1;j<n;j++){
        N[j-c]=N[j];
      }
      for(j=0;j<c;j++){
        N[n-j-1]=C[j];
      }
      
    }
    /* for(i=0;i<n;i++){
      printf("%d ",N[i]);
      }*/
    X[ss]=N[n-1];
    ss++;
  }
  for(i=0;i<ss;i++){
    printf("%d\n",X[i]);
    }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector> 
using namespace std;
int main(){
  int n, r, p, c;
  

  while(1){
    
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    int i;
    int a[n], temp[n];
    for(i = 1;i < n+1;i++){
      a[n-i] = i;
    }

    for(int j = 0;j < r;j++){
      cin >> p >> c;
      
      
      
      for(i = 0;i < c;i++){
        temp[i] = a[p-1+i];
        //cout << "temp[n-p-c+i] = " << temp[n-p-c+i] << "a[n-p-1+i] = " << a[n-p-1+i] << endl;
      }
      for(i = 0;i < p-1;i++){
        temp[c+i] = a[i];
      } 
      for(i = 0;i < n-p-c+1;i++){
        temp[c+p-1+i] = a[c+p-1+i];
      }
      for(i = 0;i < n;i++){
        a[i] = temp[i];
      }
      
    }
    
    cout << temp[0] << endl;

  }

  return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[n];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
		}
		for(int i=0; i<r; i++){
			cin >> p;
			cin >> c;
			int tmp[c];
			for(int i=0; i<c; i++){
				tmp[i] = huda[p+i-1];
			}
			for(int i=p-2; i>=0; i--){
				huda[i+1] = huda[i];
			}
			for(int i=0; i<c; i++){
				huda[i]=tmp[i];	
			}
		}
		cout << huda[0] << "\n";
	}
}

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-1);
      s = t+v+u;
    }
    cout << s[0] << endl;
  }

  return 0;
}