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 <cstdio>
#include <vector>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef vector<int> V;

int n, r;
V x;

int main(){
	while(scanf("%d%d", &n, &r), n){
		rep(i, n){
			x.push_back(n - i);
		}
		
		rep(i, r){
			int p, c;
			scanf("%d%d", &p, &c);
			V::iterator a = x.begin() + p - 1;
			V::iterator b = a + c;
			vector<int> y(a, b);
			x.erase(a, b);
			x.insert(x.begin(), y.begin(), y.end());
		}
		printf("%d\n", x[0]);

		x.clear();
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r,p1,c;
int huda[51],huda2[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>p1>>c;
                        for(int j=0; j<n; j++) {
                                huda[i]=n-i;
                                huda2[i]=huda[i];
                        }
                        for(int j=0; j<c; j++) {
                                huda[j]=huda[p1-1+j];
                        }
                        for(int j=0; j<p1-1; j++) {
                                huda[c+j]=huda2[j];
                        }
                        for(int j=0; j<51; j++) {
                                huda2[j]=huda[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}

C++: #include <iostream>
#include <cstdlib>
#include <queue>
#define INF (2<<29)
using namespace std;

typedef struct _node {
    _node* next;
    int n;
} Node;

Node* h;
int n,r,p,c;

Node* initNode(){
    Node* head = (Node*)malloc(sizeof(Node));
    head->n = n;
    Node* bef;
    bef = head;
    for(int i = n-1; i >= 1; i--){
        Node* tmp = (Node*)malloc(sizeof(Node));
        tmp->n = i;
        bef->next = tmp;
        bef = tmp;
    }
    return head;
}

// void freeNode(Node* n){
//     if(n->next != NULL) freeNode(n->next);
//     free(n);
// }

void pc(){
    Node *n1,*n2,*n3,*n4;
    // cout<<"[INFO]SHUFFLE-BEGIN"<<endl;
    if(p==1 && c==n) return;
    n1 = h;
    for(int i = 0; i < p-2; i++){ //p-1??????=n1
        n1 = n1->next;
    }
    n2 = n1->next; //p??????=n2
    
    // cout<<"p = "<<n2->n<<endl;
    
    n3 = n1;
    for(int i = 0; i < c; i++){ //p+c??????=n3
        n3 = n3->next;
        // cout<<"hoge"<<endl;
    }
    n4 = n3->next;
    n1->next = n4;
    n3->next = h;
    h = n2; //head???n2???
    // cout<<"[INFO]SHUFFLE-END"<<endl;
}

int main(void){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    for(;;){
        cin>>n>>r;
        if(n==0 && r==0) break;
        h = initNode();
        for(int i = 0; i < r; i++){
            cin>>p>>c;
            // cout << "p=" << p << ",c=" << c << endl;
            pc();
        }
        cout<<h->n<<endl;
        // cout<<"??????"<<endl;
    }

    return 0;
}

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

int main(){
	
	int n,r;
	while(cin>>n>>r){
		if(n!=r!=0){
		int h[51]={0},m[51]={0};
		int p,d;
		for(int i=0;i<n;i++)
			h[i+1]=n-i;
		while(r>0){
			cin>>p>>d;
			int j=d;
			for(int i=p+d-1;i>=p;i--)
				m[j--]=h[i];
			for(int i=p-1;i>0;i--)
				h[i+d]=h[i];
			for(int i=d;i>0;i--)
				h[i]=m[i];
			r--;
	}
			cout<<h[1]<<endl;
	}
	else
		break;
	}
	
}

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

int main(){
  int n=1,r=1,p,c;
  vector<int> deck,temp,ans;

  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=n; i>0; --i)deck.push_back(i); //???????????????
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      copy(deck.begin()+p-1,deck.begin()+p+c-1,back_inserter(temp));
      deck.erase(deck.begin()+p-1,deck.begin()+p+c-1);
      copy(deck.begin(),deck.end(),back_inserter(temp));
      deck=temp;
      temp.clear();
    }
    ans.push_back(deck[0]);
    deck.clear();
  }
  for(auto x: ans)cout << x << endl;
  return 0;
}

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

int main(){
  int n,r, start, end;
  vector<int> ans;
  cin >> n >> r;
  while(n||r){
    vector<int> data(n);
    for(int i = 0; i <n;i++){
      data[i] = n-i;
    }
    for(int j = 1; j <= r ; j++){
      cin >> start >> end;
      for(int k = 0; k < end;k++){
        int a = data[start+k-1];
        for(int forth = start-1; forth > k; forth--){
          data[k+forth] = data[k+forth-1];
        }
        data[k] = a;
      }
    }
    ans.push_back(data[0]);
    cin >> n >> r;
  }
  for(int i =0;i<ans.size();i++){
    cout << ans[i] << endl;
  }
}

C++: 
#include<bits/stdc++.h>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
    if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
            
        }
    for(int j=1;j<=y[i]/2;j++){
int remainder=card[j];
card[j]=card[y[i]-j];
card[y[i]-j]=remainder;
}
    }
 
    ans[counter]=card[0];
 counter+=1;
}
  
  
  
int main (){
counter=0;
    while(input()){
    solve();
    }
for(int j=0;j<=counter;j++){
cout<<ans[counter]<<endl;
}
return 0;
}

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

using namespace std;
int main(void){
   int field[3][51],n,r;
   while(scanf("%d%d",&n,&r),n+r){
      for(int i = 0;i < n;i++){field[0][i] = n-i-1;}
      for(int i = 0;i < r;i++){
         int p,c;scanf("%d%d",&p,&c);
         for(int j = 0;j < p-1;j++){
            field[2][j] = field[0][j];
         }
         for(int j = 0;j < c;j++){
            field[1][j] = field[0][p-1+j];
         }
         for(int j = 0;j < c;j++){
            field[0][j] = field[1][j];
         }
         for(int j = 0;j < p-1;j++){
            field[0][c+j] = field[2][j];
         }
      }
      printf("%d\n",field[0][0]+1);
   }
   return 0;
}

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

using namespace std;

int main(){
	while(true){
		vector<int> yama;
		int n,r;
		cin >> n >> r;
		if(n==0&&r==0)return 0;
		for(int i=n;i>0;i--){
			yama.push_back(i);
		}
		for(int i=0;i<r;i++){
			int p,c;
			vector<int> next;
			cin >> p >> c;
			p--;
						
			for(int k=p;k<p+c;k++){
				next.push_back(yama[k]);
			}
			for(int k=0;k<p;k++){
				next.push_back(yama[k]);
			}
			for(int k=p+c;k<n;k++){
				next.push_back(yama[k]);
			}
			yama=next;
		}
		cout << yama[0] <<endl;
	}
}