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)
	}
}

Python: temp = True
i = 0
N = []
M = []
while True:
    p,c = map(int, input().strip().split(' '))
    if p == 0 and c == 0:
        break
    if temp:
        n = p
        r = c
        for j in range(n):
            N.append(n-j)
        temp = False
    else:
        for j in range(c):
            M.append(N[p+j-1])
        for j in range(p-1):
            M.append(N[j])
        for j in range(n-c-p+1):
            M.append(N[j+c+p-1])
        N = M
        M = []
        i = i + 1
        if i == r:
            print(N[0])
            temp = True
            N = []
            i = 0

Python: while True:
    n,r = map(int, raw_input().split())
    if n==0: break
    card = range(n,0,-1)
    for i in range(r):
        p,c = map(int, raw_input().split())
        block = card[p-1:p+c-1]
        del card[p-1:p+c-1]
        card = block + card
    print(card[0])

Python: cond = [int(n) for n in input().split(" ")]

while True:
    case = []
    cards = [n for n in range(1,cond[0] + 1)]
    cards.sort(reverse = True)
    for c in range(cond[1]):
        case = [int(n) for n in input().split(" ")]
        case[0] -= 1
        #print(cards[case[0]:case[0]+case[1]],cards[case[1]:case[0]+case[1]],cards[:case[1]],cards[:case[1]])
        disp = cards[case[0]:case[0]+case[1]]
        cards[case[1]:case[0]+case[1]] = cards[0:case[0]]
        cards[0:case[1]] = disp
    else:
        print(cards[0])
        cond = [int(n) for n in input().split(" ")]
        if cond[0] == 0 and cond[1] == 0:
            break
        else:
            continue

Python: while True :
  n, r = map(int, input().split())
  if(n == 0 and r == 0) :
    break
  else :
    card = list()
    for i in range(n) :
      card.append(i + 1)
    card = card[::-1]
    for i in range(r) :
      p, c = map(int, input().split())
      card = card[p-1:p+c-1] + card[:p-1] + card[p + c - 1:]
      # スライス
    print(card[0])

Python: while 1:
    n, r = map(int, input().split())
    if n+r < 1 : break
    *l, = range(n, 0, -1)
    for i in [0]*r:
        p, c = map(int, input().split())
        p -= 1
        l = l[p:p+c] + l[:p] + l[p+c:]
    print(l[0])

Python: first = input().split()
n = int(first[0])
r = int(first[1])
while n != 0 or r != 0:
    i = 0
    card = list(range(n))
    while i < r:
        sh = input().split()
        p, c = list(map(int,sh))
        card = card[p-1:p+c-2:] + card[0:p-2:] + card[p+c-1:n:]
        i = i + 1
    print(n - int(card[0]))
    next = input().split()
    n, r = list(map(int,next))

Python: while True:
    amount, count = map(int, input().split())
    if amount == 0 and count == 0:
        break

    cards = [i for i in reversed(range(1, amount + 1))]

    for _ in range(count):
        p_th, length = map(int, input().split())
        swapper = cards[p_th - 1:p_th + length - 1]
        cards[p_th - 1:p_th + length - 1] = []
        cards[0:0] = swapper

    print(cards[0])

Python: #!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array


def operation(p, c, cards):
    return cards[p - 1: p + c - 1] + cards[:p - 1] + cards[p + c - 1:]


if __name__ == "__main__":
    while True:
        n, r = map(int, input().split())
        if n == 0 and r == 0:
            break
        else:
            cards = array.array("B", range(n, 0, -1))
            for i in range(r):
                p, c = map(int, input().split())
                cards = operation(p, c, cards)
            print(cards[0])

Python: while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break

    l = []
    for i in range(1, n + 1):
        l.append(i)

    for i in range(0, r):
        p, c = map(int, input().split())
        tmp = l[len(l) - p + 1:len(l)]
        del l[len(l) - p + 1:len(l)]
        l[len(l) - c:len(l) - c] = tmp

    print(l[len(l) - 1])

Python: while True:
    n, r = map(int, input().split())
    if n == 0:
        break
    card = list(range(n, 0, -1))
    for i in range(r):
        p, c = map(int, input().split())
        t = card[p-1:p+c-1]
        del(card[p-1:p+c-1])
        card[0:0] = t
    print(card[0])

Python: # Hanafuda Shuffle

ans = []

while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break

    deck = [i + 1 for i in range(n)]
    deck.reverse()
    for i in range(r):
        p, c = map(int, input().split())
        p -= 1
        deck = deck[p:p+c] + deck[:p] + deck[p+c:]
    ans.append(deck[0])

for i in ans:
    print(i)

Python: while True:
    n,r = map(int,input().split())
    if(n==0): break
    cards = list(range(n,0,-1))
    for i in range(r):
        p,c = map(int,input().split())
        cards = cards[p-1:p+c-1] + cards[:p-1] + cards[p+c-1:]
    print(cards[0])

Python: def main():
	while True:
		n,r=map(int,input().split())
		if n==0 and r==0:
			break
		ls=list(range(n,0,-1))
		for i in range(r):
			p,c=map(int,input().split())
			p-=1
			tmp=ls[p:p+c]
			del ls[p:p+c]
			ls=tmp+ls
		print(ls[0])


if __name__=="__main__":
	main()

Python: while True:
  n, r = map(int, input().split())
  if n==0 and r==0:
    break

  yama = [i for i in range(n, 0, -1)]
  for _ in range(r):
    p, c = map(int, input().split())
    up, bottom = [], []
    up.extend(yama[p-1:p+c-1])
    up.extend(yama[:p-1])
    bottom.extend(yama[p+c-1:])
    up.extend(bottom)
    yama = up[:]
  print(yama[0])

Python: while True:
    n,r=map(int,input().split())
    if n==0:exit()
    l=[n-i for i in range(n)]
    for j in range (r):
        p,c=map(int,input().split())
        l=l[p-1:p+c-1]+l[:p-1]+l[p+c-1:]
    print(l[0])

Python: while True:
    n, r = map(int, input().split())
    if (n,r) == (0,0):
        break
    else:
        cards = [i for i in range (1, n+1)]
        cards.reverse()
        for i in range (r):
            p,c = map(int,input().split())
            top = cards[0 : p-1]
            mid = cards[p-1 : p+c-1]
            btm = cards[p+c-1:]
            cards = mid + top + btm
        print(cards[0])

Python: while True:
    n, r = map(int, input().split())
    if n + r < 1:
        break
    mountain = list(range(1, n+1))
    for i in range(r):
        p, c = map(int, input().split())
        mountain = mountain[:n-p-c] + mountain[p-1:] + mountain[-(p-1+c):-(p-1)]
    print(mountain[-1])

Python: while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break
    cards = [i + 1 for i in range(n)]
    cards.reverse()
    for _ in range(r):
        p, c = map(int, input().split())
        new_cards = cards[p - 1 :p - 1 + c] + cards[0:p - 1] + cards[p - 1 + c:]
        cards = new_cards
    print(cards[0])

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

using namespace std;

int main(){
  int n,r;
  while(cin >> n >> r,n+r){
    int buff1[n];
    int buff2[n];
    int *cards=buff1,*next=buff2;

    /* initialize */
    for(int i=0;i<n;i++){
      cards[i]=n-i;
    }

    /* operation */
    while(r --> 0){
      int p,c,m;
      cin >> p >> c;
      m=c;

      for(int i=0;i<n;i++){
        if(i>=p-1 && i<p+c-1){
          /* to the top */
          next[i-p+1]=cards[i];
        }else{
          /* not to the top */
          next[m++]=cards[i];
        }
      }
      swap(cards,next);
    }

    cout << cards[0] << endl;
  }
  return 0;
}