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

int main()
{
  while(1){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0){
      break;
    }else{
      stack <int> x, y, z;
      while(!x.empty())
	x.pop();
      for(int i = 1; i <= n; i++)
	x.push(i);
      for(int i = 0; i < r; i++){
	int p, c;
	cin >> p >> c;
	for(int j = 1; j < p; j++){
	  y.push(x.top());
	  x.pop();
	}
	for(int j = 0; j < c; j++){
	  z.push(x.top());
	  x.pop();
	}
	while(!y.empty()){
	  x.push(y.top());
	  y.pop();
	}
	while(!z.empty()){
	  x.push(z.top());
	  z.pop();
	}
      }
      cout << x.top() << endl;
    }
  }
}

C++: #include<iostream>

using namespace std;

int main(){

   while(1){

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

      cout<< a[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){
    //?±±??????????????????                                                            
    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;
}

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);
  }
}

C++: #include <iostream>
using namespace std;
 
int n, r, p, c;
int cards[64];
 
void init() {
    for(int i = 0; i < n; i++)
        cards[i] = n - i;
}
 
bool input() {
    cin >> n >> r;
    if(!n && !r)
        return false;
    return true;
}
 
void shuffle() {
    int tmp[64];
    
    // c 個分の要素をtmpに格納
    for(int i = 0; i < c; i++)
        tmp[i] = cards[p - 1 + i];
    // p-1 個分の要素を c 個分ずらす
    for(int i = 0; i < p - 1; i++)
        cards[p - 2 - i + c] = cards[p - 2 - i];
    // 先頭に c 個分の要素をつめる
    for(int i = 0; i < c; i++)
        cards[i] = tmp[i];
}
 
int solve() {
    for(int i = 0; i < r; i++) {
        cin >> p >> c;
        shuffle();
    }
    return cards[0];
}
 
int main() {
    while(input()) {
        init();
        cout << solve() << endl;
    }
    return 0;
}

C++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1e18;

V<int> b[55];

V<int> f(V<int> a,int p,int c,int n){
    V<int> b;
    for(int i=p-1;i<p-1+c;i++){
        b.push_back(a[i]);
    }
    for(int i=0;i<p-1;i++) b.push_back(a[i]);
    for(int i=p-1+c;i<n;i++) b.push_back(a[i]);
    return b;
}

signed main(){
    while(true){
        int n,r;
        cin>>n>>r;
        if(n==0&&r==0) break;
        V<int> a,ans;
        for(int i=n;i>0;i--) a.push_back(i);
        for(int i=1;i<=r;i++){
            int p,c;
            cin>>p>>c;
            if(i==1) b[i]=f(a,p,c,n);
            else b[i]=f(b[i-1],p,c,n);
        }
        cout<<b[r][0]<<endl;
    }
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	} 

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]-c[i]+1)>=ans){
		}else if(ans>=(n-c[i]+1)){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	}

	printf("%d\n",ans);

	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<long long,int> P;
static const int INF=1<<24;

int a[50];

int main(){
	int n,r;
	while(cin>>n>>r,!(n==0&&r==0)){
		rep(i,n+1){
			a[i]=n-i;
		}
		int p,c;
		int t1[50]={0},t2[50]={0};
		
		rep(i,r){
			cin>>p>>c;
			for(int j=0;j<c;j++){
				t1[j]=a[j+p-1];
				//cout<<t1[j]<<endl;
			}
			//cout<<endl;
			for(int j=0;j<p-1;j++){
				t2[j]=a[j];
			}
			for(int j=0;j<c;j++){
				a[j]=t1[j];
			}
			for(int j=0;j<p-1;j++){
				a[j+c]=t2[j];
			}
			/*
			rep(j,n){
				cout<<a[j]<<" ";
			}
			cout<<endl;
			*/
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

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

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

#define INF 1000000007LL
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)

int n,r,p[55],c[55];

int main(){
	while(cin>>n>>r && n){
		rep(i,r)cin>>p[i]>>c[i];
		int x=1;
		for(int i=r-1;i>=0;i--){
			if(x<=c[i])x+=p[i]-1;
			else if(x<=c[i]+p[i]-1)x-=c[i];
		}
		cout<<n+1-x<<endl;
	}
}

C++: //#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int input(char s[]);

int main() {
	int n, r,brk=0,p,c,x[50],xs[50];
	for (int i = 0; i < 50; i++)
		x[i] = xs[i] = i;

	while (1) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0)
			brk = 1;
		for (int i = 0; i < r&&brk == 0; i++) {
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++)
				x[j] = xs[j + p - 1];
			for (int j = c; j < c + p - 1; j++)
				x[j] = xs[j - c];
			for (int j = 0; j < n; j++)
				xs[j] = x[j];}
		if (brk == 1)
			break;
			printf("%d\n", n-x[0]);
	}
	return 0;
}