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<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
struct ml{
  int dt;
  struct ml *nx;
};
typedef struct ml Ml;
void f(Ml *a,int p,int q){
  int i;
  Ml *b,*c,*d;
  b=a;
  for(i=0;i<p-1;i++)
    b=b->nx;
  c=b;
  for(i=0;i<q;i++)
    c=c->nx;
  d=a->nx;
  a->nx=b->nx;
  b->nx=c->nx;
  c->nx=d;
  return;
}
int main(){
  int i;
  int n,r,p,q;
  Ml *a;
  while(cin>>n>>r&&n+r){
    a=(Ml*)malloc((n+2)*sizeof(Ml));
    for(i=0;i<n+1;i++){
      (a+i)->dt=n-i+1;
      (a+i)->nx=a+i+1;
    }
    (a+i)->dt=n-i+1;
    for(i=0;i<r;i++){
      cin>>p>>q;
      if(p!=1)
	f(a,p,q);
    }
    cout<<a->nx->dt<<endl;
    free(a);x
  }
  return 0;
}

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

using namespace std;

int main(){
  

  while(1){
    int n,r;
    cin>>n>>r;

    if(n==0 && r==0)break;
    
    int x[n];

    int p,c,k=0;


    for(int i=0;i<n;i++){
      k++;
      x[i]=k;
    }

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

C++: #include <string>
#include <iterator>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

string GetStr()
{
	string str;
	getline(cin,str);
	return str;
}

vector<int> GetIntVector()
{
	string str;
	getline(cin,str);
	istringstream line( str );

	istream_iterator<int> iit(line);
	istream_iterator<int> iit_eof;

	vector<int> ret;

	for(;iit != iit_eof; iit++){
		ret.push_back(*iit);
	}

	return ret;
}

typedef struct 
{
	int n,count;
} HANAFUDA;

HANAFUDA GetSituation()
{
	HANAFUDA h;
	vector<int> v = GetIntVector();
	h.n = v[0];
	h.count = v[1];

	return h;
}

bool true_func(int dummy){return true;}

void solve(HANAFUDA h)
{
	vector<int> data(h.n);
	for(int i = 0; i < h.n; i++){
		data[i] = h.n - i;
	}

	for(int i = 0; i < h.count; i++){
		vector<int> inputs = GetIntVector();
		rotate( data.begin(), data.begin() +(inputs[0] - 1), data.begin() + (inputs[0] + inputs[1] - 1) );
	}

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

void Hanafuda()
{
	HANAFUDA h = GetSituation();
	while(h.n != 0 && h.count != 0){
		solve(h);
		h = GetSituation();
	}
}


int main()
{
	Hanafuda();

	return 0;
}

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

int main(){
	int n,r;
	while(cin>>n>>r &&n && r){
		vector<int>data;
		for(int i=1;i<=n;i++)data.push_back(i);
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			stack<int>st;
			for(int j=0;j<c;j++){
				
				int tmp=data[n-p];
				data.erase(data.begin()+n-p++);
				st.push(tmp);
				
				}
			
			while(!st.empty()){
				data.push_back(st.top());st.pop();
			}
		}
		cout<<data[n-1]<<endl;
	}
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i];
  }
  cout << endl;
}

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

int main(){
  int n,r,p,c;

  while(cin >> n >> r , n + r){
    vector<int> cards;

    for(int i = n ; i >= 1 ; i--){
      cards.push_back(i);
    }

    while(r--){
      cin >> p >> c;
      vector<int> tmp;
      for(int i = p-1 ; i < p+c-1 ; i++){
	tmp.push_back(cards[i]);
	cards[i] = -1;
      }
   
      for(int i = 0 ; i < cards.size() ; i++){
	if(cards[i] != -1) tmp.push_back(cards[i]);
      }

      for(int i = 0 ; i < n ; i++){
	cards[i] = tmp[i];
      }

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

  return 0;
}

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

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

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

using namespace std;
int main(){
    int n,r,p,c;
    while(true){
        cin >> n >> r;
        if(n==0 && r==0){
            break;
        }
        vector<int> a(n);
        for (int i=0;i<n;i++){
            a[i]=n-i;
        }
        for(int i=0;i<r;i++){
            cin >> p >> c;
            rotate(a.begin(),a.begin()+p-1,a.begin()+p+c-1);
            for (int i=0;i<n;i++){
            }
        }
        cout << a[0] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main() {
	int n, r, a, b, temp, s=0, t=0;
	while(1){
		cin >> n >> r;
		int p[n];
		if(n==0 && r==0) break;
		for(int i=0; i<n; i++){
			p[i]=n-i;
		}
		for(int i=0;i<r; i++){
			cin >> a >> b;
			for(int j=0; j<b; j++){	
				for(int k=a-1+t;k>s;k--){
					temp=p[k];
					p[k]=p[k-1];
					p[k-1]=temp;
				}
				s++;
				t++;
			}
			s=0;
			t=0;
		}
		cout << p[0] << endl;
	}
}

C++: #include<cstdio>
int main(void){
  int n, r, p, c;
  int card[64], w[64];
  for( ; ; ){
    scanf("%d %d", &n, &r);
    if(!(n + r)) break;
    for(int i = 1;i <= n; i++) card[n - (i - 1)] = i;
    for(int j = 0;j < r; j++){
      scanf("%d %d", &p, &c);
      for(int i = 1;i <= n; i++) w[i] = card[i];
      for(int i = c + 1;i < c + p; i++) card[i] = w[i - c];
      for(int i = 1;i <= c; i++) card[i] = w[i + p - 1];
    }
    printf("%d\n", card[1]);
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repb(i, n) for(int i = n;i >= 0;i--)
#define reps(i, m, n) for(int i = m;i < n;i++)
#define repsb(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main(){
	int n,p,c,r;
	while(true)
	{
		cin>>n>>r;
		if(n==0)	return 0;
		int b[50];
		rep(i,n){
			b[i]=n-i;
		}

		rep(s,r){
			int a[50],j;
			cin>>p>>c;
			for(j=0;j<c;j++){
				a[j]=b[p+j-1];
			}
			for(;j<p+c-1;j++){
				a[j]=b[j-c];
			}
			for(;j<n;j++){
				a[j]=b[j];
			}
			rep(t,n){
				b[t]=a[t];
			}
		}
		cout<<b[0]<<endl;
	}

	return 0;
}