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<cstdio>
#define N 50
using namespace std;

int main(){

  int n,r,ans;
  int operate[N][2];

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

      for(int i=0;i<r;i++)cin >> operate[i][0] >> operate[i][1];
      ans = n;
      int da = n;
     
      for(int i=r-1;i>=0;i--){
	da = n;
	if(n-operate[i][1] <= ans && ans <= n)
	  {
	    if(n == operate[i][1])continue;
	    ans = ans-operate[i][0]+1;
	  
	  }
	else{
	  da = da-operate[i][0]+1;
	  if(da <= ans)ans+=operate[i][1];
	  //else if(da > ans)ans-=operate[i][1];

	}
	//cout << "da ~ " << da << endl;
	//cout << "ans = " << ans << endl;

      }

      cout << ans << endl;



    }

}

C++: #pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 998244353
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int n,r;cin>>n>>r;
    while(n&&r){
        int a[51];
        for(int i=0;i<n;i++)a[i]=n-i;
        for(int i=0;i<r;i++){
            int p,c;cin>>p>>c;
            p--;
            ll l=p,r=p+c-1;
            V<ll>move;
            for(ll j=l;j<=r;j++){
                move.pb(a[j]);
                //cout<<a[j]<<endl;
            }
            for(ll j=l-1;j>=0;j--){
                a[j+c]=a[j];
            }
            for(ll j=0;j<c;j++){
                a[j]=move[j];
            }
        }
        cout<<a[0]<<endl;
        cin>>n>>r;
    }
    //-------------------------------  
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    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>
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;
}