Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r){
		if(n==0 && r==0) break;
		string str(n,0);
		for(int i=0;i<str.length();i++){
			str[i]=n-i;
		}
		for(int j=0;j<r;j++){
			int p,c;
			cin>>p>>c;
			str=str.substr(p-1,c)+str.substr(0,p-1)+str.substr(p+c-1);
		}
		cout<<(int)str[0]<<endl;
	}
	return 0;
}

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

int main(void){
    while(true){
        int n=0, r=0, yama[55], tmp[55];
        cin >> n >> r;
        if(n==0 && r==0) break;
        for(int i=0;i<n;++i) yama[i] = n-i;
        for(int i=0;i<r;++i){
            int p, c;
            cin >> p >> c;
            for(int j=0;j<p-1;++j) tmp[j] = yama[j];
            for(int j=0;j<c;++j) yama[j] = yama[p-1+j];
            for(int j=0;j<p-1;++j) yama[c+j] = tmp[j];
        }
        cout << yama[0] << endl;
    }
}

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

int main()
{
	int n, r;
	while (cin >> n >> r, n + r)
	{
		deque<int> ary;
		for (int i = 1; i <= n; i++) ary.push_front(i);

		while (r--)
		{
			int p, c;
			cin >> p >> c;
			int i = p + c - 2;
			while (c--)
			{
				int tmp = ary[i];
				ary.erase(ary.begin() + i);
				ary.push_front(tmp);
			}
		}

		cout << ary.front() << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std; 
int main()
{
  int n, cut;
  int A[50],B[50],i,j,p,c;
  while(1){
      cin>>n>>cut;
      if(n==0&&cut==0)break;
      else{
      for(i=0; i<=n-1; i++)A[i]=n-i;
      while(cut--){
          cin>>p>>c;
          for(j=0; j<n; j++)B[j]=A[j];
          for(j=0; j<p-1; j++)B[j+c]=A[j];
          for(j=0; j<c;j++)B[j]=A[j+p-1];
          for(j=0; j<n;j++)A[j]=B[j]; 
        }}
      cout<<A[0]<<endl;}
      return 0;
    }

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

int main() {
	vector<int> d;
	int n, r, p, c, tmp;
	cin >> n >> r;
	while(n != 0) {
		d.resize(n);
		for (int i = 0;i < n;i ++) d[i] = i + 1;
		for (int i = 0;i < r;i ++) {
			cin >> p >> c;
			for (int j = 0;j < c;j ++) {
				tmp = d[n - p - c + 1];
				d.erase(d.begin() + n - p - c + 1);
				d.push_back(tmp);
			}
		}
		cout << d[n - 1];
		cin >> n >> r;
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int a[51]={};
  int st[51]={};
  int n,r;
  int p,c;
  while(1){
    //in
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++){
      a[i]=n-i;
    }
    for(int i=0;i<r;i++){
      cin >> p >>c; 
      for(int j=0;j<n;j++){
	st[j]=a[j];
      }
      for(int j=0;j<c;j++){
	a[j]=st[p+j-1];
      }
      for(int j=0;j<p-1;j++){
	a[j+c]=st[j];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n, r;
        cin >> n >> r;
        if(n == r && r == 0) break;
        int p[55];
        int c[55];
        for(int i = 1; i <= r; i++) cin >> p[i] >> c[i];
        int pos = 1;
        for(int i = r; i >= 1; i--) {
            if(pos > c[i] + p[i] - 1) continue;
            if(pos <= c[i]) {
                pos += p[i] - 1;
                continue;
            }
            pos -= c[i];
        }
        cout << n + 1 - pos << 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++: //19
#include<iostream>
#include<cstring>

using namespace std;

int main(){
  for(int n,r;cin>>n>>r,n|r;){
    int card[50];
    for(int i=0;i<n;i++){
      card[i]=n-i;
    }
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      int temp[50];
      memcpy(temp,card,sizeof(card[0])*(p-1));
      memmove(card,card+p-1,sizeof(card[0])*c);
      memcpy(card+c,temp,sizeof(card[0])*(p-1));
    }
    cout<<card[0]<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
    int n, r, p[64], c[64];
    while (scanf("%d%d", &n, &r), n | r)
    {
	for (int i = 0; i < r; ++i)
	    scanf("%d%d", p + i, c + i);

	int pos = 1;
	for (int i = r - 1; i >= 0; --i)
	{
	    if (pos <= c[i])
		pos += p[i] - 1;
	    else if (pos <= c[i] + p[i] - 1)
		pos -= c[i];
	}
	printf("%d\n", n - (pos - 1));
    }
}

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

using namespace std;
int n, r, p, c;

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