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 <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1};

int main() {
	int n, r;
	while(cin >> n >> r, n|r){
		vi list(n);
		REP(i, n) list[i] = i + 1;

//		for(auto n:list)
//			LOG("%d ", n);
//		LOG("\n");

		REP(i, r){
			int p, c;
			cin >> p >> c;
			vi stk = {list.end()-(p+c-1),list.end()-(p-1)};
			list.erase(list.end()-(p+c-1),list.end()-(p-1));
			for(auto n:stk)
				list.push_back(n);

//			for(auto n:list)
//				LOG("%d ", n);
//			LOG("\n");
		}

		cout << list[list.size() - 1] << endl;
	}
}

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

int main(){

  int n, r;
  for(;cin >> n >> r, n|r;){
    vector < int > v;
    for(;n;v.push_back(n--));
    for(int p,c;r--;){
      cin >> p >> c;
      for(int tmp,q=c;q--;){
	tmp = v[p+c-2];
	v.erase(v.begin()+p+c-2);
	v.insert(v.begin(), tmp);
      }
    }

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

}

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

using namespace std;

int main(){
  int n,r;
  int p,c;
  while(1){
    cin >> n >> r;
    if(n == 0) break;
    vector<int> A(n);
    for(int i = 0; i< n; i++){
      A[i] = n -i;
    }
    for(int i = 0; i < r; i++){
      cin >> p >> c;
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
       for(int j = 0; j< n;j++){
	cout<< A[j];
	}
    }
    cout << A[0]<< endl;
  }
  return 0;
}

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

int main()
{
	int n, r, p, c;
	
	while(cin >> n >> r && n>0)
		{
			//山を作る
			int A[n];
			for(int i = 0; i<n; i++){ A[i] = n-i; }
			
			//表示
			//for(int i = 0; i<n; i++){ cout << A[i] << " "; }
			//cout << endl;
			
			for(int i = 0; i<r; i++)
			{
				cin >> p >> c;
				rotate(&A[0], &A[p-1], &A[p+c-1]);
				
				//表示
				//for(int i = 0; i<n; i++){ cout << A[i] << " "; }
				//cout << endl;
			}
			cout << A[0] << endl;
		}
}

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

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

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


void shuffle(int a, int b, int *ans)
{
    int t[a];
    a--;
    for (int i = 0; i < a; i++) {
        t[i] = ans[i];
    }
    for (int i = a; i < a + b; i++) {
        ans[i - b] = t[i - e];
    }
    for (int i = b; i < a + b; i++) {
        ans[i] = t[i - b];
    }
}
int main()
{
    int n,r;
    while (cin >> n >> r, n) {
        int ans[n];
        for (int i = 0; i < n; i++) {
            ans[i] = n - i;
        }
        for (int i = 0; i < r; i++) {
            int b, e;
            cin >> b >> e;
            shuffle(b, e, ans);
        }
        cout << ans[0] << endl;

    }

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++){
		after[i]=0;
		tmp[50]=0;
	}
}

bool input(){	
	int i;
	cin>>n>>r;
	for(i=0;i<n;i++)
		before[i]=i+1;	
	return 1;
}



int solve(){
	int j;
	for(int i=0;i<r;i++){
		cin>>p>>c;
		for(j=0;j<c;j++){
			after[n-1-j]=before[n-p-j];
			tmp[n-1-j]=before[n-p-j];
		}
		for(j=0;j<p;j++){
			after[n-1-c-j]=before[n-1-j];
			tmp[n-1-c-j]=before[n-1-j];
		}
		for(j=0;j<n;j++)
			before[j]=tmp[j];
	}
	return after[n-1];
}


int main(){
	n=r=1;
  while((n!=0)&&(r!=0)){
	init(),input();
	cout<<solve()<<endl;
  }
  return 0;
}

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

#define rep(i,n) for (int i = 0; i < int(n); ++i)

int n,r,p,c,a[50];

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

C++: #include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;


int main(){
	while(1){
		int n,r,p,c;
		cin>>n>>r;
		if(n==0)break;
		int ans=0;
		vl s(110),t(110);
		rep(i,1,n+1)s[i]=n-i+1;
		rep(i,0,r){
			cin>>p>>c;
			t=s;
			rep(j,1,p+c+1){
				if(j<=c)s[j]=t[p+j-1];
				else if(j>c&&j<p+c)s[j]=t[j-c];
			}
		}
		print(s[1]);
	}
	return 0;
}

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

void shuffle( vector <int>& deck, int p, int c )
{
    vector <int> cut( c );
    copy( deck.begin() + p - 1, deck.begin() + p + c - 1, cut.begin() );
    deck.erase( deck.begin() + p - 1, deck.begin() + p + c - 1 );
    deck.insert( deck.begin(), cut.begin(), cut.end() );
}

int main( void )
{
    int n, r;
    while ( cin >> n >> r && n && r )
    {
        vector <int> deck( n );
        for ( int i = 0; i < n; i++ ) deck[i] = n - i;

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

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

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

int main()
{
  int n, r;
  for ( ; ; ) {
    cin >> n >> r;
    if (n == 0 && r == 0)
      break;

    vector<int> Card;
    for (int i = n; i > 0; --i)
      Card.push_back(i);

    for (int i = 0; i < r; ++i) {
      int p, c;
      cin >> p >> c;
      vector<int> Card_new;
      for (int j = 0; j < c; ++j) {
	Card_new.push_back(Card[p-1]);
	Card.erase(Card.begin() + p - 1);
      }
      for (unsigned int j = 0; j < Card.size(); ++j)
	Card_new.push_back(Card[j]);
      Card = Card_new;
    }
    cout << Card[0] << endl;
  }
  return 0;
}