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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n,r;
	while(scanf("%d %d",&n,&r),n) {
		vector<int> v;
		for(int i=0;i<n;i++) {
			v.push_back(n-i);
		}
		for(int i=0;i<r;i++) {
			int p,c;
			scanf("%d %d",&p,&c);
			vector<int> a,b;
			for(int j=0;j+1<p;j++) {
				int e=v.front();v.erase(v.begin());
				a.push_back(e);
			}
			for(int j=0;j<c;j++) {
				int e=v.front();v.erase(v.begin());
				b.push_back(e);
			}
			for(int j=p-2;j>=0;j--) {
				v.insert(v.begin(),a[j]);
			}
			for(int j=c-1;j>=0;j--) {
				v.insert(v.begin(),b[j]);
			}
		}
		printf("%d\n",v[0]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;

int n, r;

struct opt {
	int p, c;
};

vector<opt> V;

int main() {
	while(cin >> n >> r, n | r) {
		V.clear();

		rep(i, r) {
			opt o;
			cin >> o.p >> o.c;
			V.push_back(o);
		}

		int a = 1;
		repd(i,V.size()-1,0) {
			if(a <= V[i].c) {
				a += V[i].p-1;
			} else {
				if(a - V[i].c <= V[i].p - 1) {
					a = a - V[i].c;
				}
			}
		}
		printf("%d\n", n-a+1);
	}
}

C++: #include <iostream>
#include <vector>
 
using namespace std;
 
void solve()
{
    int n, r;
    while(cin >> n >> r, n || r)
    {
        vector<int> Vec(n);
        for(int i = 0; i < n; ++i)
        {
            Vec[i] = n - i;
        }
        while(r--)
        {
            int p, c;
            cin >> p >> c;
            vector<int> VecBuf = Vec;
            int pos = 0;
            for(int i = p - 1; i < p + c - 1; ++i)
            {
                Vec[pos] = VecBuf[i];
                ++pos;
            }
            for(int i = 0; i < p - 1; ++i)
            {
                Vec[pos] = VecBuf[i];
                ++pos;
            }
            // for(int i = p + c - 1; i < n; ++i)
            // {
            //     Vec[pos] = VecBuf[i];
            //     ++pos;
            // }
        }
        cout << Vec[0] << endl;
    }
}
 
int main()
{
    solve();
    return(0);
}

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>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
typedef unsigned long ulong;

void solve() {
	vector<int> res;
	while (true) {
		int n, r;
		cin >> n >> r;
		if (n == r && n == 0)break;

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

		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			vector<int> ps;
			vector<int> cs;
			for (int j = 0; j < p - 1; j++)ps.push_back(card[j]);
			for (int j = 0; j < c; j++) {
				card[j] = card[j + p - 1];
			}
			for (int j = 0; j < p - 1; j++)card[j + c] = ps[j];
		}
		res.push_back(card[0]);
	}
	for (int i = 0; i < res.size(); i++)cout << res[i] << endl;
}

int main()
{
	solve();
	return 0;
}

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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <array>

using namespace std;

int A[51];
int n,m,p,c;

int main(){
    while(true){
        cin >> n >> m;
        if(n+m == 0)break;
        for(int i = 0;i < n;i++)A[i] = n - i;
        for(int i = 0;i < m;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);
//            for(int k = 0;k < n;k++){
//                cout << A[k] << " ";
//            }
//            cout << endl;
        }
        cout << A[0] << endl;
    }
}

C++: #include <cstdio>

int n, r;
int card[55], tmp[55];

int main(){
	while(scanf("%d%d", &n, &r)){
		if(n == 0 && r == 0) break;
		for(int i = 0; i < n; i++) card[i] = n-i;
		for(int i = 0; i < r; i++){
			int p,c; scanf("%d%d", &p, &c); p--;
			for(int i = p; i < p+c; i++) tmp[i-p] = card[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];
		}
		printf("%d\n", card[0]);
	}
}

C++: using namespace std;

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

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

        for(int i=0;i<r;i++){
            cin >> p >> c;
            rotate(a,a+p-1,a+p+c-1);
        }
    cout << a[0] << endl;
    }

    return 0;

}