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<bits/stdc++.h>
using namespace std;
int x[100];
int y[100];
int card [100];
int ans[100];
int n,r,counter;
int main (){
    counter=0;
    while(input()){
    solve();
    }
for(int i=0;i<counter;i++){
cout<<ans[i]<<endl;
}
return 0;
}
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;
        }
    }
    ans[counter]=n-card[0]+1;
    counter++;
}

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

int main()
{
  int n, r;
  while( cin >> n >> r, n && r ) {
    int card[51];
    for(int i=n-1; i>=0; i--) card[i] = n-i-1;

    while( r-- ) {
      int p, c;
      int tmp[51];
      cin >> p >> c;
      for(int i=0; i<n; i++) tmp[i] = card[i];

      for(int i=0; i<c; i++) card[i] = tmp[i+p-1];
      for(int i=c; i<c+p-1; i++) card[i] = tmp[i-c];
    }

    cout << card[0] + 1  << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  while(1){
    int n,r,a,b,yama[51],tmp[51];
    cin>>n>>r;
    if(n+r==0)break;
    for(int i=0;i<=n;i++)yama[i]=i;
    for(int i=0;i<r;i++){
      cin>>a>>b;
      for(int j=0;j<b;j++)tmp[j]=yama[n-(a+b-2)+j];
      for(int j=0;j<a-1;j++)yama[n-(a+b-2)+j]=yama[n-a+2+j];
      for(int j=0;j<b;j++)yama[n-b+1+j]=tmp[j];
    }
    cout<<yama[n]<<endl;
  }
  return 0;
}

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

signed main() {
	while (true) {
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		vector<int> a(n);

		for (int i = 0; i < n; i++) a[i] = i + 1;

		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			rotate(a.end() - (p - 1) - c, a.end() - (p - 1), a.end());
		}

		cout << a[n - 1] << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)

int main() {
	int N,R;
	while(cin>>N>>R && N>0 && R>0){
		int p[R],c[R];
		Rep(i,R) cin>>p[i]>>c[i];
		int card[N];
		Rep(i,N) card[i] = N - i;
		Rep(i,R) rotate(card,card+p[i]-1,card+p[i]+c[i]-1);
		cout<<card[0]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)
#define for(i, j, k) for(int i = j; i < k; i++)

int main(){
  int n, r;
  while(cin >>n >>r && n){
    vector<int> v;
    for(int i = n; i > 0; i--) v.push_back(i);

    rep(i, r){
      int p, c;
      cin >>p >>c;
      vector<int> next;
      for(int i = 0; i < c; i++) next.push_back(v[p - 1 + i]);
      for(int i = 0; i < p - 1; i++) next.push_back(v[i]);
      for(int i = p + c - 1; i < v.size(); i++) next.push_back(v[i]);
      v = next;
    }
    cout <<v[0] <<endl;
  }
  return 0;
}

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){
    //?±±??????????????????                                                            
    yama.clear();
    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] << endl;
  }
  cout << endl;
}

void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);
    for(int j = 0; j < yama.size(); j++){
      cout << yama[j] << " ";
    }
    cout << endl;

  }
}

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

int main() {
  while(true) {
    int ncard, r;
    cin >> ncard >> r;
    if(ncard == 0 && r == 0) break;
    vector<int> cards(ncard);
    for(int i = 0; i < ncard; ++i) cards[i] = ncard - i;
    for(int i = 0; i < r; ++i) {
      int p, c;
      vector<int> results;
      scanf("%d%d", &p, &c);
      for(int j = p - 1; j < p - 1 + c; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = 0; j < p - 1; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = p - 1 + c; j < ncard; ++j) {
        results.push_back(cards[j]);
      }
      cards = results;
    }
    cout << cards[0] << endl;
  }
  return 0;
}