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

int solve(int n,int r){
  vector<int> l;
  for(int i=0;i<n;i++){
    l.push_back(i+1);
  }
  l = vector<int>(l.rbegin(),l.rend());
  for(int i=0;i<r;i++){
    int p,c;
    cin>>p>>c;
    vector<int> l1,l2;
    for(int j=0;j<l.size();j++){
      if(j<p-1){
        l1.push_back(l[j]);
      }else if(j<p+c-1){
        l2.push_back(l[j]);
      }else{
        l1.push_back(l[j]);
      }
    }
    for(int j=0;j<l1.size();j++){
      l2.push_back(l1[j]);
    }
    l = l2;
    //for(auto i:l)cout<<i<<" ";cout<<endl;
  }
  return l[0];
}


int main(){
  int n,r;
  while(cin>>n>>r,n!=0&&r!=0){
    cout<<solve(n,r)<<endl;
  }

}

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

bool solve(){
    int n, r;
    cin >> n >> r;
    if(n == 0) return false;
    vector<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;
        p--;
        vector<int> tmp(c);
        for(int j=0;j<c;j++){
            tmp[j] = a[p+j];
        }
        a.erase(a.begin()+p, a.begin()+p+c);
        a.insert(a.begin(), tmp.begin(), tmp.end());
    }
    cout << a.front() << endl;
    return true;
}

int main(){
    while(solve());
    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()-1; i++){
    cout << v[i] << endl;
  }
  cout << v[v.size()-1];
  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<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <functional>
using namespace std;
typedef pair<int,int> mypair;

int main(void){
int n,r;
while(1)
{
cin>>n>>r;
if(n==0)break;
vector<mypair> huda(n);
mypair temp;
for(int i=0;i<n;i++){
	temp.first=n-i;
temp.second=n-i;
huda[i]=temp;
}


int p,c;
for(int i=0;i<r;i++){
	cin>>p>>c;
	for(int j=0;j<p-1;j++)
	huda[c+j].first=huda[j].second;
	for(int j=0;j<c;j++)
	huda[j].first=huda[p-1+j].second;
	for(int j=0;j<n;j++){
		huda[j].second=huda[j].first;
	}
	
}
//for(int i=0;i<n;i++)
//cout<<huda[i].first<<' '<<huda[i].second<<endl;
cout<<huda[0].second<<endl;
}
return 0;
}

C++: #include <cstdio>
#include <cstring>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
int n,r;
int f[55],cp[55];
int main(void){
	for(;;){
		scanf("%d%d",&n,&r);
		if(n==0)break;
		rep(i,0,n)f[i]=n-i;
		rep(i,0,n)printf("%d ",f[i]);
			printf("\n");
		rep(i,0,r){
			int a,b;
			scanf("%d%d",&a,&b);
			memcpy(cp,f,(a-1)*4);
			memcpy(f,f+a-1,b*4);
			memcpy(f+b,cp,(a-1)*4);
		}
		printf("%d\n",f[0]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    while(1){
        int n,r;
        cin >> n >> r;
        if(n==0){
            break;
        }
        vector<int> vec(n,0);
        vector<int> vec1(n,0);
        for(int i=0;i<n;i++){
            vec[i]=n-i;
            vec1[i]=vec[i];
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin >> p >> c;
            p--;
            for(int j=0;j<c;j++){
                vec1[j]=vec[j+p];
            }
            for(int j=c;j<p+c;j++){
                vec1[j]=vec[j-c];
            }
            for(int j=0;j<n;j++){
                vec[j]=vec1[j];
               // cout<< vec[j]<<endl;
            }
          //  cout<<endl;
        }
        cout<< vec[0]<<endl;
        //cout<<endl<<endl;
    }
}

C++: #include <stdio.h>

int main(void){
	int n, r, card[50], i, j, k, tmp, p, c;
	scanf("%d%d",&n,&r);
	while(n != 0 || r != 0){
		for(i = 0;i < n;i++)
			card[i] = n - i;
		for(k = 0;k < r;k++){
			scanf("%d%d",&p,&c);
			for(i = 0;i < c;i++){
				tmp = card[p - 1 + i];
				for(j = p - 1 + i;j > i;j--)
					card[j] = card[j - 1];
				card[i] = tmp;
			}
		}
		printf("%d\n",card[0]);
		scanf("%d%d",&n,&r);
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;
int num1[50],num2[50];
void sets(int N);
void change(int p,int c);
int main()
{
    int N,r,i,j,p,c;
    for(;scanf("%d%d",&N,&r),N+r!=0;)
    {
        sets(N);
        for(i=0;i<r;i++)
        {
            scanf("%d%d",&p,&c);
            change(p,c);
        }
        printf("%d\n",num1[0]);
    }
    return 0;
}
void sets(int N)
{
    for(int i=0,j=N;i<N;i++,j--)
    {
        num1[i]=j;
    }
}
void change(int p,int c)
{
    int i;
    for(i=0;i<p-1;i++)num2[c+i]=num1[i];
    for(i=0;i<c;i++)num2[i]=num1[p-1+i];
    for(int i=0;i<c+p-1;i++) num1[i] = num2[i];
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N, R;
  while (cin>>N>>R, N+R!=0) {
    vector<int> x;
    for (int i = 0; i < N; i++) x.push_back(i+1);
    for (int i = 0; i < R; i++) {
      int p, c; cin>>p>>c;
      p = N-p-c+1;
      for (int j = 0; j < c; j++) {
        x.push_back(x[p]);
        x.erase(x.begin()+p);
      }
    }
    cout << x.back() << endl;
  }
}

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

int main() {
	while(true){
		int n,r;
		cin>>n>>r;
		if(n==0&&r==0) return 0;
		vector<int>v(n+5);
		for(int i=0;i<n;i++) v[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			vector<int>u(p-1);
			vector<int>l(c);
			for(int i=0;i<p-1;i++) u[i]=v[i];
			for(int i=p-1;i<p-1+c;i++) l[i-(p-1)]=v[i];
			for(int i=0;i<c;i++) v[i]=l[i];
			for(int i=c;i<c+p-1;i++) v[i]=u[i-c];
		}
		cout<<v[0]<<endl;
	}
	return 0;
}

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

int main(){
    int n,r;
    for(int i = 0;;i++){
        scanf("%d%d",&n,&r);
        if(n == 0 && r == 0){
            break;
        }
        int hanafuda[n];
        for(int j = 0;j < n;j++){
            hanafuda[j] = j + 1;
        }
        for(int j = 0;j < r;j++){
            int p,c;
            scanf("%d%d",&p,&c);
            if(c == n){
                continue;
            }
            for(int k = 0;k < c;k++){
                for(int K = 0;;K++){
                    if(p - k + K == n){
                        break;
                    }
                    std::swap(hanafuda[p - k + K - 1],hanafuda[p - k + K]);
                }
            }
        }
        printf("%d\n",hanafuda[n - 1]);
    }
}