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>
using namespace std;

int main(){
  int n;
  int r;
  while(cin>>n>>r && n+r){
    vector<int> vec;
    vec.resize(n);
    for(int i=0;i<n;i++){
      vec[i]=n-i;
    }

    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      p--;
      vector<int> v;
      v.resize(c);
      for(int j=0;j<c;j++){
	v[j]=vec[p+j];
      }
      for(int j=p-1;j>=0;j--){
	vec[j+c]=vec[j];
      }
      for(int j=0;j<c;j++){
	vec[j]=v[j];
      }
    }
    cout<<vec[0]<<endl;

  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int ans[1000];
int n,r,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;
    }
    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;
        }
    }
    ans[counter]=n-card[0];
    counter++;
}
 
 
 
int main (){
    counter=0;
    while(input()){
    solve();
    }
    for(int i=0;i<counter;i++){
    cout<<ans[i]<<endl;
    }
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
typedef long long ll;

int N, R, P[50], C[50];
int a[51][50];

int main(void) {
  while(cin >> N>>R, N || R) {
    REP(i, 0, R)cin >>P[i]>>C[i];
    REP(i, 0, N) a[0][i] = N - i;
    REP(i, 0, R){
      REP(j, 0, C[i]) a[i + 1][j] = a[i][P[i] + j - 1];
      REP(j, 0, P[i] - 1) a[i + 1][C[i] + j] = a[i][j];
      REP(j, C[i] + P[i] - 1, N) a[i + 1][j] = a[i][j];
      // REP(j, 0, N) {
      //     cout << a[i + 1][j] << " ";
      // }
      // cout << endl;
    }
    cout << a[R][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;
    }
    cout << s[0] << endl;
  }

  return 0;
}

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

int main(){
  int n,r;
  int array1[50],array2[50];

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

    for(int i=0;i<n;i++) array1[n-i-1]=array2[n-i-1]=i+1;

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

      for(int i=0;i<p;i++){
	swap(array1[c-1+i],array1[i]);
	array2[c-1+1]=0;
      }
      
      for(int i=p;i<n;i++){
	if(array2[i]==0)i++;
	array1[i]=array2[i-p];
      }

    }
    
    cout<<array1[0]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int n, r;
  while(scanf("%d%d", &n, &r) && n+r){
    vector<int>vi(n);
    int t = n;
    rep(i, n) vi[i] = t--;
    int p, c;
    while(r--){
      scanf("%d%d", &p, &c);
      p--;
      vector<int>tmp;
      rep(i, c){
	tmp.push_back(vi[p]);
	vi.erase(vi.begin()+p);
      }
      vi.insert(vi.begin(), tmp.begin(), tmp.end());
      /*      puts("");
      rep(i, n){
	printf("%d ", vi[i]);
	}*/
    }
    printf("%d\n", vi[0]);
  }
  return 0;
}

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


int card[50];
struct CUT{
  int p;
  int c;
};

CUT cut[51];
int swap_p[50];
int swap_c[50];
int n,r;
void solve(){
  for(int i = 0; i < n; i++){
    card[i] = n - i;
  }

  for(int i = 0; i < r ; i++){
   /* for(int x = 0; x < n; x++){
      cout << card[x] << " ";
    }
    cout << endl;
    */
    for(int j = 0; j < cut[i].p; j++) swap_p[j] = card[j];
    for(int k = 0; k < cut[i].c; k++) swap_c[k] = card[cut[i].p + k - 1];
    for(int l = 0; l < cut[i].p + cut[i].c - 1;l++){
      if(cut[i].c > l)  card[l] = swap_c[l] ;
      else              card[l] = swap_p[ l - cut[i].c ];
    }
  }
  cout << card[0] << endl;
  return ;
}



int main(){
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    for(int input = 0; input < r; input++){
      cin >> cut[input].p >> cut[input].c ;
    }
    solve();
  }
  return 0;
}

C++: #include<iostream>
#include<stack>
#include<queue>

using namespace std;

void solve(stack <int> s , int r ){
  
  
  int p[r] ,c[r];

  for(int i = 0 ; i < r ; i++ ){
    cin >> p[i] >> c[i];
    p[i]--;
  }
  
  for(int i = 0 ; i < r ; i++ ){
    stack<int> s_sita;
    stack<int> s_ue;
    
    

    while(p[i]-- > 0){
      int a = s.top();
      s.pop();
      //cout << "push_sita:" << a << endl;
      //cout << "p:" << p[i] << endl;
      //cout << "size" << s.size() << endl;
      s_sita.push(a);
    }

    while(c[i]-- > 0){
      int a =s.top();
      s.pop();
      //cout << "push_ue:" << a << endl;
      //cout << "c" << c[i] << endl;
      //cout << "size" << s.size() << endl;
      s_ue.push(a);
    }
    
    while(!s_sita.empty()){
      s.push(s_sita.top());
      //cout << "s.push" << s_sita.top() << endl;
      s_sita.pop();
    }
    
    while(!s_ue.empty()){
      s.push(s_ue.top());
      //cout << "s.push" << s_ue.top() << endl;
      s_ue.pop();
    }
    
    //cout << "size" << s.size() << endl;

    //cout << endl;

  }
    
  cout << s.top() << endl;

  return;

}

int main(){

  int r , n ;

  
  while(1){

    cin >> n >> r;
    if(r == 0 || n == 0)
      break;

    else{
      stack <int> s;
      for(int i = 1 ; i <= n ; i++ ){
        s.push(i);
        //cout << i << endl;
      }
      solve(s,r);
      //cout << "done" << endl;
    }
  }

  return 0;
}

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

vector<int> cut(vector<int> crd,int p,int c){
  vector<int> ret = crd;
  for(int i=0;i<c;++i) ret[i] = crd[i+p];
  for(int i=0;i<p;++i) ret[c+i] = crd[i];
  return ret;
}

int main(){
  int n,k;
  while(cin>>n>>k,n||k){
    vector<int> crd;
    for(int i=n;i>=1;--i) crd.push_back(i);
    while(k--){
      int p,c;
      cin >> p >> c;--p;
      crd = cut(crd,p,c);
    }
    cout << crd[0] << endl;
  }
  return 0;
}

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];

void init(){
	for(int i=0;i<50;i++)
		before[i]=after[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;
		after[i]=n-i;
	return true;
}

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


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


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