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 <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s

int main()
{
	int n, r;
	while (cin >> n >> r, n)
	{
		int p, c;
		vector<int> deck;
		vector<int> tmp;
		REP(i, n) deck.push_back(n - i);
		REP(s, r)
		{
			tmp = deck;
			cin >> p >> c;
			REP(i, c)
			{
				deck[i] = tmp[p + i - 1];
			}
			REP(i, p - 1)
			{
				deck[i + c] = tmp[i];
			}

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

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

using namespace std;

void solve(stack <int> s , int r ){
  
  
  int p[r] ,c[r];

  for(int i = 0 ; i < r ; i++ ){
    cin >> p[i] >> c[i];
    p[i]--;
  }
  
  for(int i = 0 ; i < r ; i++ ){
    stack<int> s_sita;
    stack<int> s_ue;
    
    

    while(p[i]-- > 0){
      int a = s.top();
      s.pop();
      //cout << "push_sita:" << a << endl;
      //cout << "p:" << p[i] << endl;
      //cout << "size" << s.size() << endl;
      s_sita.push(a);
    }

    while(c[i]-- > 0){
      int a =s.top();
      s.pop();
      //cout << "push_ue:" << a << endl;
      //cout << "c" << c[i] << endl;
      //cout << "size" << s.size() << endl;
      s_ue.push(a);
    }
    
    while(!s_sita.empty()){
      s.push(s_sita.top());
      //cout << "s.push" << s_sita.top() << endl;
      s_sita.pop();
    }
    
    while(!s_ue.empty()){
      s.push(s_ue.top());
      //cout << "s.push" << s_ue.top() << endl;
      s_ue.pop();
    }
    
    //cout << "size" << s.size() << endl;

    //cout << endl;

  }
    
  cout << s.top() << endl;

  return;

}

int main(){

  int r , n ;

  
  while(1){

    cin >> n >> r;
    if(r == 0 || n == 0)
      break;

    else{
      stack <int> s;
      for(int i = 1 ; i <= n ; i++ ){
        s.push(i);
        //cout << i << endl;
      }
      solve(s,r);
      //cout << "done" << endl;
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
int  main(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(n==0&& r==0) break;
    int a[51],b[51];
    lp(i,51){
      a[i]=i;
    }
    lp(i,r){
      lp(j,51){
	b[j]=0;
      }
      int c,d;
      cin>>c>>d;
      for(int j=n;j>n-c+1;j--){
	b[j-d]=a[j];
      }
      for(int j=n-c+1;j>n-c-d;j--){
	b[j+c-1]=a[j];
      }
      for(int j=1;j<=n;j++){
	if(b[j]!=0){
	  a[j]=b[j];
	}
      }
    }
    cout<<a[n]<<endl;
  }
  return 0;
}

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

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

int n, m;
int data[100];

void shuffle(int x, int y){
  int dst[100];
  for(int i=x-1;i<x-1+y;++i){
    dst[i-x+1]=data[i];
  }
  for(int i=x-2;i>=0;--i){
    data[i+y]=data[i];
  }
  for(int i=0;i<y;i++){
    data[i]=dst[i];
  }
}

void init(){
  rep(i,n)
    data[i]=n-i;
}

int main() {
  while(true){
    scanf("%d%d",&n,&m);
    if (!n&&!m)break;
    init();
    rep(_,m) {
      int x, y;
      scanf("%d%d",&x,&y);
      shuffle(x,y);
    }
    printf("%d\n",data[0]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n, r;
	int card[55];
	int a[55], b[55];
	while(cin >> n >> r, n+r){
		rep(i, n) card[i] = n-i;
		int p, c;
		for(int i=0; i< r; i++){
			rep(i, 55){ a[i] = 0; b[i] = 0;}
			cin >> p >> c;

			rep(i, p-1) a[i] = card[i];
			rep(i, c) b[i] = card[p+i-1];
			rep(i, c) card[i] = b[i];
			rep(i, p-1) card[i+c] = a[i];

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

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

int main(){
  int card1[50],card2[50];
  int n,r;
  int p,c;

  while(1){
    cin>>n>>r;
    if(n+r==0)break;
    for(int i=0;i<n;i++)  card1[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>p>>c;
      for(int i=0;i<c;i++) card2[i]=card1[p-1+i];
      for(int i=c;i<p;i++) card2[i]=card1[i-c];
      if(p>=c){
	for(int i=p;i<n;i++){
	  if(p+c-1==n) card2[i]=card1[i-c];
	  else card2[i]=card1[i-1+c];
	}
      }
      for(int i=0;i<n;i++)card1[i]=card2[i];
    }
    cout<<card2[0]<<endl;
  }

  return 0;
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	int n, r, p, c;

	while(true) {
		cin >> n >> r;
		if(n == 0 && r == 0) break;

		std::vector<int> cards(n);

		for(int i = 0; i < n; ++i) {
			cards.at(n - i - 1) = i + 1;
		}

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

			std::vector<int> temp_p;
			std::vector<int> temp_c;

			std::copy_n(cards.begin(), p - 1, std::back_inserter(temp_p));
			std::copy_n(cards.begin() + p - 1, c, std::back_inserter(temp_c));

			std::copy(temp_c.begin(), temp_c.end(), cards.begin());
			std::copy(temp_p.begin(), temp_p.end(), cards.begin() + c);
		}

		std::cout << cards.at(0) << std::endl;
	}

	return 0;
}

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

int main() {
  int N, R, P, C;
  while (cin >> N && cin >> R && N > 0 && R > 0) {
    int n[N];
    for (int i = 0; i < N; i++) n[i] = N-i;

    while (R > 0) {
      cin >> P; 
      cin >> C;
      rotate(n, n+P-1, n+P+C-1);
      R--;
    }
        cout << n[0] << endl;
  }
  
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e09

using namespace std;

int main(){
  int n, r;
  while(cin >> n and cin >> r and n+r){
    vector<int> card(n);
    iota(ALL(card), 1);
    reverse(ALL(card));
    REP(i, r){
      int p, c;
      cin >> p >> c;
      p--;
      int tmp[c];
      REP(j, c) tmp[j] = card[p+j];
      for(int j=p-1; j>=0; j--) card[j+c] = card[j];
      REP(j, c) card[j] = tmp[j];
    }
    cout << card[0] << endl;
  }
  return 0;
}

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

int main(){
  int n=1,r=1,p,c;
  vector<int> deck,temp,ans;

  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=n; i>0; --i)deck.push_back(i); //???????????????
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      copy(deck.begin()+p-1,deck.begin()+p+c-1,back_inserter(temp));
      deck.erase(deck.begin()+p-1,deck.begin()+p+c-1);
      copy(deck.begin(),deck.end(),back_inserter(temp));
      deck=temp;
      temp.clear();
    }
    ans.push_back(deck[0]);
    deck.clear();
  }
  for(auto x: ans)cout << x << endl;
  return 0;
}

C++: #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  int n,r;
  while(cin>>n>>r){
    if(n==0 && r==0) return 0;
    
    vector<pair<int,int>> A(n);
    rep(i,n) A[i]={i,n-i};
    
    int p,c;
    rep(i,r){
      cin>>p>>c;
      for(int j=p-1;j<p+c-1;j++){
        A[j].first=j-p+1;
      }
      for(int j=0;j<p-1;j++){
        A[j].first=c+j;
      }
      sort(ALL(A));
    }
    cout<<A[0].second<<endl;
  }
  
  return 0;
}