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

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

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

int main(){
  int card[50],tmp[50];
  int n,r,p,c;

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

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

      for(int i=0;i<c;i++)tmp[i] = card[p-1+i];
      for(int i=p-1;i>=0;i--)card[i+c] = card[i];
      for(int i=0;i<c;i++)card[i] = tmp[i];
    }
    cout << card[0] << endl;
  }
}

C++: //#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#define INF INT_MAX / 2
using namespace std;

typedef pair<double, double> P;
typedef long long ll;

vector<int> cut(vector<int> vi,int p,int c){
	vector<int> ret;
	for(int i=p-1;i<p-1+c;i++)
		ret.push_back(vi[i]);
	for(int i=0;i<p-1;i++)
		ret.push_back(vi[i]);
	for(int i=p+c-1;i<vi.size();i++)
		ret.push_back(vi[i]);
	return ret;
}

int main(void) {
	int n;int r;

	while(cin >> n >> r,n+r!=0){
	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;
		a = cut(a,p,c);
	}
	cout << a[0] << endl;
}
}

// command ctrl 上下
// command D
// command caps G → '' ""

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]=a[j+p];
      }

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

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

int main(){
  int n,r;

  while(cin>>n>>r,n||r){
    vector<int> v;
    REP(i,1,n+1) v.push_back(i);
    rep(i,r){
      int p,c;
      cin>>p>>c;

      rep(j,c){
        int tmp = v[n-p-c+1];
        v.erase(v.begin() + (n-p-c+1));
        v.push_back(tmp);
      }
    }

    cout<<v[n-1]<<endl;
  }
}

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

#define gcu getchar_unlocked
#define ii inline int in
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
//void scan(string &s) {for (char c; !isspace(c = gcu()); s += c);}
inline bool scan(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo

struct operation {int p, c;};

int main() {
	int n, r;
	while (scan(n) && scan(r) && (n || r)) {
		stack<operation> op;
		while (r--) {
			int p = in(), c = in();
			op.push({p, c});
		}
		int top = 1;
		while (!op.empty()) {
			auto o = op.top();
			op.pop();
			if (top <= o.c)
				top += o.p - 1;
			else if (top - o.c < o.p)
				top -= o.c;
		}
		out(n - top + 1, '\n');
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  int n,r;
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    int d[51];
    //?????????
    for(int i=0;i<n;i++){
      d[i]=n-i;
    }

    if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
    if(debug)cout<<endl;
      
    for(int i=0;i<r;i++){
      int p,c,tmp[51];
      cin>>p>>c;
      
      for(int j=0;j<c;j++)tmp[j]=d[j+p-1];

      for(int j=p-2;j>=0;j--)d[j+c]=d[j];

      for(int j=0;j<c;j++)d[j]=tmp[j];

      
      if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
      if(debug)cout<<endl;
    }
    
  }
  return 0;
}

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

int main()
{
	int n,r;
	while(cin>>n>>r){
		if(n==0) return 0;
		vector<int> V;
		for(int i=0;i<n;i++)
			V.push_back(n-i);

		for(int i=0;i<r;i++){
			int s,t;
			cin>>s>>t;
			s--;

			vector<int> w;
			for(int j=0;j<t;j++){
				w.push_back(V[s+j]);
			}

			vector<int> next;

			for(int k=0;k<w.size();k++){
				next.push_back(w[k]);
			}

			for(int k=0;k<s;k++){
				next.push_back(V[k]);
			}

			for(int k=s+t;k<n;k++)
				next.push_back(V[k]);

			V=next;
		}
		cout<<V[0]<<endl;


	}
}

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi st(n);
		REP(i, n)
			st[i] = n-i ;

		REP(i, r) {
			vi sw(n);
			REP(i, n)
				sw[i] = st[i];
			int p, c;
			cin >> p >> c;
			REP(j, c)
				sw[j] = st[p-1  + j];
			REP(j, p-1)
				sw[j + c] = st[j];


			REP(i, n)
				st[i] = sw[i];

		}

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

	return 0;
}

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

int main(){
	int n,r;
	int p,c;
	int yama[50];
	int workspace[50];

	while(1){
		cin >> n >> r;

		if(n==0&&r==0) break;

		for(int i=1;i<=n;i++){
			yama[i-1] = i;
		}

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

			for(int i=0;i<=n;i++){
				workspace[(n-1)-i] = yama[(n-1)-i];
			}

			for(int i=0;i<=(c-1);i++){
				yama[(n-1)-i] = yama[(n-1)-i-(p-1)];
			}

			for(int i=0;i<=((p-1)-1);i++){
				yama[(n-1)-i-c] = workspace[(n-1)-i];
			}

		}

		cout << yama[n-1] << endl;
	}
}

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

int deck[64], buf[64];

int main(){
    int n, r, p, c;
    while (1){
	cin >> n >> r;
	if (n == 0 && r == 0) break;

	for (int i = 0; i < n; i++){
	    deck[i] = n - i; buf[i] = n - i;
	}

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

	    // for blue
	    for (int j = 0; j < p-1; j++){
		buf[c+j] = deck[j];
	    }
	    // for orange
	    for (int j = 0; j < c; j++){
		buf[j] = deck[p-1+j];
	    }
	    for (int j = p + c - 1; j < n; j++){
		buf[j] = deck[j];
	    }

	    for (int m = 0; m < n; m++) deck[m] = buf[m];
	}
	cout << deck[0] << endl;

    }
}