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

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int inf=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > p;

int n,r;
void solve() {
    vector<int> hana;
    for(int i=n;i>=1;i--) hana.pb(i);
    rep(i,r) {
        int p,c;
        cin>>p>>c;
        vector<int> tmp;
        for(int i=0;i<p-1;i++) tmp.pb(hana[i]);
        for(int i=0;i<c;i++) hana[i] = hana[i+p-1];
        for(int i=c;i<c+p-1;i++) hana[i]=tmp[i-c];
        //rep(i,hana.size()) cout<<hana[i]<<" ";
        //cout<<endl;
    }
    cout<<hana[0]<<endl;
}
int main() {
    while(cin>>n>>r) {
        if(n+r==0) break;
        solve();
    }

    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[51];
		int tmp1[51],tmp2[51];
		for(int i=0;i<n;++i)card[i]=(n-i);
		for(int i=0,p,c;i<r;++i){
			cin>>p>>c;
			for(int j=0;j<p-1;++j)tmp1[j]=card[j];
			for(int j=p-1;j<p+c-1;++j)tmp2[j-(p-1)]=card[j];
			for(int j=0;j<c;++j)card[j]=tmp2[j];
			for(int j=c;j<c+p-1;++j)card[j]=tmp1[j-c];
		}
		cout<<(card[0])<<"\n";
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <list>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n,r;
  while(cin>>n>>r,n+r) {
    vector<int> a;
    REP(i,n)
      a.push_back(i+1);
    REP(i,r) {
      int p, q;
      cin >> p >> q;
      REP(j,q) {
        a.push_back(a[n-p-q+1]);
        a.erase(a.end()-p-q);
      }
      // FOR(j,a)
      //   cout << *j << " ";
      // cout << endl;
    }
    cout << a[n-1] << endl;
  }
}

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

using namespace std;

int main()
{
	int n, r;
	vector<int> p, c;
	vector<int> fuda1, fuda2;
	
	
	while (true)		//１データセットに対する処理を１ループで行う
	{
		scanf("%d %d", &n, &r);
		if (n==0) return 0;
		
		p.resize(r);
		c.resize(r);
		fuda1.resize(n);
		fuda2.resize(n);
		
		for (int i=0; i<r; i++)
		{
			scanf("%d %d", &p[i], &c[i]);
		}
		
		//fuda1の初期化
		for (int i=0; i<n; i++)
		{
			fuda1[i] = n - i;
		}
		
		//シャッフル
		for (int i=0; i<r; i++)		//iはシャッフルの回数
		{
			for (int i2=0; i2<c[i]; i2++)
			{
				fuda2[i2] = fuda1[(p[i]-1)+i2];
			}
			
			for (int i2=0; i2<p[i]-1; i2++)
			{
				fuda2[c[i]+i2] = fuda1[i2];
			}
			
			for (int i2=0; i2<(n-(p[i]+c[i]-1)); i2++)
			{
				fuda2[p[i]+c[i]-1+i2] = fuda1[p[i]+c[i]-1+i2];
			}
			
			for (int i2=0; i2<n; i2++)
			{
				fuda1[i2]=fuda2[i2];
			}
		}
		
		printf("%d\n", fuda1[0]);
	}
	
	return 0;
}

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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


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

        stack<int> st;
        for(int i=1; i<=n; i++) st.push(i);

        for(int i=0; i<r; i++){
            int p, c;
            cin >> p >> c;
            vector<int> v1;
            vector<int> v2;
            for(int j=0; j<p-1; j++){
                v1.push_back(st.top());
                st.pop();
            }
            for(int j=0; j<c; j++){
                v2.push_back(st.top());
                st.pop();
            }
            for(int j=0; j<p-1; j++){
                st.push(*(v1.end()-1));
                v1.pop_back();
            }
            for(int j=0; j<c; j++){
                st.push(*(v2.end()-1));
                v2.pop_back();
            }
        }

        cout << st.top() << endl;

    }
}

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define iter(c) __typeof((c).begin())
#define each(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define URU(y) (!(y % 4) && y % 100 || !(y % 400))

using namespace std;

typedef pair<int, int> PII;
typedef long long LINT;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;

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

int main ( void )
{
	// cin.tie( 0 );
	// ios::sync_with_stdio( false );
	int n, r;
	while ( cin >> n >> r, n | r ) {
		VI cards( n );
		for ( int i = 0; i < n; ++i ) {
			cards[i] = n - i;
		}
		for ( int i = 0; i < r; ++i ) {
			VI t( cards );
			int p, c;
			cin >> p >> c;
			for ( int j = 0; j + 1 < p; ++j ) {
				t[c + j] = cards[j];
			}
			for ( int j = 0; j < c; ++j ) {
				t[j] = cards[p - 1 + j];
			}
			cards = t;
		}
		cout << cards[0] << endl;
	}
	return 0;
}

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

int main(){
    int n,r;
    for(int i = 0;;i++){
        scanf("%d%d",&n,&r);
        if(n == 0 && r == 0){
            break;
        }
        int hanafuda[n];
        for(int j = 0;j < n;j++){
            hanafuda[j] = j + 1;
        }
        for(int j = 0;j < r;j++){
            int p,c;
            scanf("%d%d",&p,&c);
            if(c == n){
                continue;
            }
            for(int k = 0;k < c;k++){
                for(int K = 0;;K++){
                    if(p - k + K == n){
                        break;
                    }
                    std::swap(hanafuda[p - k + K - 1],hanafuda[p - k + K]);
                }
            }
        }
        printf("%d\n",hanafuda[n - 1]);
    }
}