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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[n];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			int tmp[c];
			for(int j=0; j<c; j++){
				tmp[j] = huda[p+j-1];
			}
			for(int j=p-2; j>=0; j--){
				huda[j+1] = huda[j];
			}
			for(int j=0; j<c; j++){
				huda[j]=tmp[j];	
			}
		}
		cout << huda[0] << "\n";
	}
}

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

using namespace std;

int A[51];
int n,m,p,c;

int main(){
    while(true){
        cin >> n >> m;
        if(n+m == 0)break;
        for(int i = 0;i < n;i++)A[i] = n - i;
        for(int i = 0;i < m;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);
//            for(int k = 0;k < n;k++){
//                cout << A[k] << " ";
//            }
//            cout << endl;
        }
        cout << A[0] << endl;
    }
}

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

#define rep(a, b, c) for(int a = b; a < c; a++ )

using namespace std;

int main() {
    while (true) {
        int N, R;
        cin >> N >> R;
        if (N == 0 && R == 0) break;
        int yama[N];
        rep(i, 0, N) {
            yama[i] = N - i;
        }
        rep(i, 0, R) {
            int P, C;
            cin >> P >> C;
            int rem[C];
            rep(j, 0, C) {
                rem[j] = yama[j + P - 1];
            }
            for (int j = P - 2; j >= 0; j--) {
                yama[j + C] = yama[j];
            }
            rep(j, 0, C) {
                yama[j] = rem[j];
            }
        }
        cout << yama[0] << endl;
    }
    return 0;
}

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

int main(void) {
	int n, r;

	while(cin >> n >> r, n || r) {
		vector<int> deck;
		
		for(int i = 0; i < n; i++) {
			deck.push_back(n - i);
		}

		for(int j = 0; j < r; j++) {
			int p, c;
			cin >> p >> c;
			vector<int> tmp(deck.begin(), deck.begin() + p);
			for(int k = 0; k < c; k++) {
				deck[k] = deck[p - 1 + k];
			}

			for(int k = c; k < p - 1 + c; k++) {
				deck[k] = tmp[k - c];
			}
		}

		cout << deck[0] << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		string str;
		for(int i=n;i>0;i--)str+=i;
		for(int i=0,p,c;i<m;i++){
			string now;
			cin>>p>>c;
			for(int j=0;j<c;j++)now+=str[p-1+j];
			for(int j=0;j<n;j++)if(j<p-1||j>p+c-2)now+=str[j];
			str=now;
		}
		cout<<str[0]<<endl;
	}
}

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

int main(){

  int card[50];
  int esc[50];
  int n,r;
  int p,c;

  while(cin >> n >> r){
    if(n==0 && r==0){ break; }
    
    for(int i=0; i<n; i++){
      card[i]=n-i;
    }

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

      /*
      cout << "prev:";
      for(int j=0; j<n; j++)cout << card[j] << ' ';
      cout << endl;
      */

      for(int j=0; j<c; j++){
	esc[j] = card[p-1+j];
      }
      for(int j=p-2; j>=0; j--){
	card[j+c]=card[j];
      }
      for(int j=0; j<c; j++){
	card[j] = esc[j];
      }

      /*cout << "now:";
      for(int j=0; j<n; j++)cout << card[j] << ' ';
      cout << endl;
      cout << "esc:";
      for(int j=0; j<c; j++)cout << esc[j] << ' ';
      cout << endl;
      */
   }

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

  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m;
struct cards
{
    int from,to;
    cards(int f,int t)
    {
        from=f,to=t;
    }
};
deque<cards> all;
deque<cards> split(int k)
{
    deque<cards> sub;
    for(;;)
    {
        cards t=all.front();
        all.pop_front();
        k -= t.to-t.from+1;
        if(k==0)
        {
            sub.pb(t);
            break;
        }
        if(k<0)
        {
            all.push_front(cards(t.to+k+1,t.to));
            t.to+=k;
            sub.pb(t);
            break;
        }
        sub.pb(t);
    }
    return sub;
}
void print(deque<cards> mount)
{
	for(int i=0;i<mount.size();i++)
	{
		cout << mount[i].from << ' ' << mount[i].to << endl;
	}
	return;
}
void shuffle(int x,int y)
{
    deque<cards> a=split(x);
    deque<cards> b=split(y);
    for(int i=a.size()-1;i>=0;i--)all.push_front(a[i]);
    for(int i=b.size()-1;i>=0;i--)all.push_front(b[i]);
}
int main()
{
    while(1)
    {
        cin >> n >> m;
        if(n==0&&m==0)break;
        all.clear();
        all.pb(cards(1,n));
        for(int i=0;i<m;i++)
        {
            int p,c;
            cin >> p >> c;
            shuffle(p-1,c);
        }
        cout << n-all[0].from+1 << endl;
    }
    return 0;
}

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

int main(){
	int n,r;
	while((cin >> n)&&(cin >> r)&&(n!=0)&&(r!=0)){
		int a[n];
		int cnt=n;
		for(int i=0;i<n;i++){
			a[i] = cnt;
			cnt--;
			//cout << "a[" << i << "]" << a[i] << endl;
		}
		int p,c;
		//cout << endl;
		for(int i=0;i<r;i++){
			cin >> p;
			cin >> c;
			int b[50];
			//cout << p << endl;
			//cout << c << endl;
			//cout << endl;
			if(n!=c){
				for(int j=0;j<p;j++){
					b[j+c] = a[j];
				}
				for(int j=0;j<c;j++){
					b[j] = a[p+j-1];	
				}
				for(int j=0;j<p+c;j++){
					a[j] = b[j];	
					//cout << "a[" << j << "]" << a[j] << endl;
				//	cout << "b[" << j << "]" << b[j] << endl;
				}
			}
		}
		cout << a[0] << 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-1; j>0; j--){
            a[j]=a[j-1];
         }
         for(int j=0; j<c; j++){
            a[j]=b[j];
         }
      }

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

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

void Shuffle(int n, int r){
	int c,p;
	int Deck[50];
	int tmp[50];
	//?±±?????????
	for(int i = 0;i < n;i++){
		Deck[i] = n - i;
	}
	//?????£?????????
	for(int i = 0; i < r; i++){
		cin >> p >> c;
		p--; //??????????????????????????????

		//p??????c???????????????????????£??????
		for(int j = 0; j < c; j++){
			tmp[j] = Deck[j + p];
		}
		//???????????????
		for(int j = p-1; j >= 0; j--){
			Deck[j+c] = Deck[j];
		}
		//?????£?????????????????????????????????
		for(int j = 0; j < c; j++){
			Deck[j] = tmp[j];
		}
	}
	cout << Deck[0] << endl;
}

int main(void){
	int n; //?±±???????????°
	int r; //???????????????????????°
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0){
			return 0;
		}
		Shuffle(n,r);
	}
	return 0;
}