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<climits>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<list>
#include<string>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int,int>
#define PCC pair<char,char>
#define PCI pair<char,int>
#define PIC pair<int,char>
#define MP make_pair
#define DEBUG(x) cout<<#x<<": "<<x<<endl

int main()
{
	while (1)
	{
		vector<int> N;
		int n, r;
		cin >> n >> r;
		for(int i=1;i<=n;i++)N.push_back(i);
		if (n == 0)break;
		REP(i, r)
		{
			int p, c;
			cin >> p >> c;
			for(int l=c;l>0;l--)
			{
				int k = n - p -c+1 ;
				int temp = *(N.begin() + k);
				N.push_back(temp);
				N.erase(N.begin() + k);
			}
		}
		cout << N[n-1] << endl;
	}
	return 0;
}

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

using namespace std;

int main(void) {
	while(1) {
		int n, r;
		int p, c;
		stack<int> deck, deck_p, deck_c;

		scanf("%d %d", &n, &r);
		if(n == 0 && r == 0) break;
		for(int i = 1; i <= n; i++) {
			deck.push(i);
		}
		for(int i = 0; i < r; i++) {
			scanf("%d %d", &p, &c);
			for(int j = 0; j < p - 1; j++) {
				deck_p.push(deck.top());
				deck.pop();
			}
			for(int j = 0; j < c; j++) {
				deck_c.push(deck.top());
				deck.pop();
			}
			for(int j = 0; j < p - 1; j++) {
				deck.push(deck_p.top());
				deck_p.pop();
			}
			for(int j = 0; j < c; j++) {
				deck.push(deck_c.top());
				deck_c.pop();
			}
		}

		printf("%d\n", deck.top());
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int n, r; cin >> n >> r;
    if (!n) break;
    V<> a(n);
    iota(begin(a), end(a), 0);
    while (r--) {
      int p, c; cin >> p >> c, --p;
      rotate(begin(a), begin(a) + p, begin(a) + p + c);
    }
    cout << n - a[0] << '\n';
  }
}

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

int main(){
	
	int n,r;
	while(cin>>n>>r){
		if(n!=r!=0){
		int h[50]={0},m[50]={0};
		int p,d;
		for(int i=0;i<n;i++)
			h[i]=n-i;
		while(r>0){
			cin>>p>>d;
			int j=d-1;
			for(int i=p+d-1;i>=p;i--)
				m[j--]=h[i-1];
			for(int i=p-1;i>0;i--)
				h[i+d-1]=h[i-1];
			for(int i=d;i>0;i--)
				h[i-1]=m[i-1];
			r--;
	}
			cout<<h[0]<<endl;
	}
	else
		break;
	}
	
}

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

using namespace std;
int n, r, p, c;

int main(){
	while (cin >> n >> r && n){
		int a[55];
		for (int i = 0; i < r; i++){
			a[i] = i + 1;
		}
		for (int j = 0; j < r; j++){
			cin >> p >> c;
			rotate(a + n - p - c + 1, a + n - p + 1, a + n);
		}
		cout << a[n - 1] << endl;
	}
	return 0;
}

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

int main() {

	int n, r, p, c;
	int h[50];
	int change[50];

		while (1) {
			cin >> n >> r;
			if (n == 0)
				break;
			for (int i = 0; i < n; i++) {
				h[i] = n - i;
			}
			for (int i = 0; i < r; i++) {
				cin >> p >> c;
				for (int j = 0; j < p; j++) {
					change[j] = h[j];
				}
				for (int j = 0; j < c; j++) {
					h[j] = h[j + p - 1];
				}
				int k = 0;
				for (int j = c; j < c + p - 1; j++) {
					h[j] = change[k];
					k++;
				}
			}
			cout << h[0] << endl;
		}


	return 0;
}

C++: #include<stdio.h>
int w[60], R, n, p, c, tw[60];
int main(){
    int i;
    while(1){
        scanf("%d%d",&n,&R);
        if(!n)break;
        for(i=1;i<=n;i++)w[i]=n-i+1;
        while(R--){
            scanf("%d%d",&p,&c);
            for(i=1;i<=n;i++)tw[i] = w[i];
            for(i=1;i<=c;i++)w[i]=tw[i+c];
            for(i=1;i<=c;i++)w[i]=tw[i+p-1];
            for(i=c+1;i<p+c;i++)w[i]=tw[i-c];
            for(i=p+c;i<=n;i++)w[i]=tw[i];
        }
        printf("%d\n",w[1]);
    }
}

C++: #include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    while(true){
        int n, r;
        cin >> n >> r;
        if(n == 0 && r == 0){
            break;
        }
        vector<int> fuda(n);
        for(int i = 0 ; i < n ; i++){
            fuda[i] = n - i;
        }
        for(int i = 0 ; i < r ; i++){
            int x, y;
            cin >> x >> y;
            x--;
            for(int j = 0 ; j < y ; j++){
                int tmp = fuda[x + j];
                fuda.erase(fuda.begin() + x + j);
                fuda.insert(fuda.begin() + j, tmp);
            }
        }
        cout << fuda[0] << endl;
    }
    return 0;
}

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

int main()
{
    int card_num;
    int shuffle_num;
    int p, c;
    while(1){
        cin >> card_num;
        cin >> shuffle_num;
        if(card_num * shuffle_num == 0){
            break;
        }
        int card[card_num];
        for(int i = 0; i < card_num; i++){
            card[i] = card_num - i;
        }
        for(int i = 0; i < shuffle_num; i++){
            cin >> p;
            cin >> c;
            rotate(card, card + p - 1, card + c + p - 1);
        }
        cout << card[0] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r){
		if(n==0&&r==0)break;
		int card[50];
		int tmp1[50],tmp2[50];
		for(int i=0;i<n;++i)card[i]=i+1;
		for(int i=0,p,c;i<r;++i){
			cin>>p>>c;
			for(int j=0;j<p;++j)tmp1[j]=card[j];
			for(int j=p;j<p+c;++j)tmp2[j]=card[j];
			for(int j=0;j<c;++j)card[j]=tmp2[j];
			for(int j=c;j<c+p;++j)card[j]=tmp1[j];
		}
		cout<<(card[0])<<"\n";
	}
	return 0;
}

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

      for(int i=0;i<n;i++){	
	a[i]=b[i];
      }
    }
    cout<<b[0]<<endl;
  }  
  return 0;
}

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-'0';
		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]+'0'<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

vector<int> shuffle(vector<int> a, int p, int c, int n)
{
  vector<int> b;

  FOR(i,p-1,p+c-1) b.push_back(a[i]);
  FOR(i,0,p-1) b.push_back(a[i]);
  FOR(i,p+c-1,n) b.push_back(a[i]);

  //REP(i,n) cout<<b[i]<<" ";

  return b;
}

int solve(int n,int r)
{
  vector<int> a;
  int p, c;

  REP(i,n) a.push_back(n-i);
  //REP(i,n) cout<<a[i]<<" ";

  REP(i,r){
    cin>>p>>c;
    a = shuffle(a, p, c, n);
  }

  return a[0];
}

int main()
{
  int n, r;

  while(1) {
    cin>>n>>r;
    if (n == 0 && r == 0) break;
    cout<<solve(n,r)<<endl;
  }


  return 0;
}