Problem:
 Problem A: Hanafuda Shuffle There are a number of ways to shuffle a deck of cards.   Hanafuda 
shuffling for Japanese card game 'Hanafuda' is one such example.
The following is how to perform Hanafuda shuffling. There is a deck of n cards. Starting from the p -th card 
from the top of the deck, c cards are pulled out
and put on the top of the deck, as shown in Figure 1.
This operation, called a cutting operation, is repeated. Write a program that simulates Hanafuda shuffling and answers which 
card will be finally placed on the top of the deck.       Figure 1: Cutting operation    Input The input consists of multiple data sets.
Each data set starts with a line containing two positive integers n (1 <= n <= 50) and r (1 <= r <= 50); n and r are the number of cards in the deck and the number of cutting 
operations, respectively. There are r more lines in the data set, each of which
 represents a cutting operation. These cutting operations 
are performed in the listed order.
Each line contains two positive integers p and c ( p + c <= n + 1).
Starting from the p -th card from the top of the deck, c cards should be pulled out and put on the top. The end of the input is indicated by a line which contains two zeros. Each input line contains exactly two integers separated by a space 
character.
There are no other characters in the line. Output For each data set in the input, your program 
should write the number of the top card after the shuffle.
Assume that at the beginning the cards 
are numbered from 1 to n , from the bottom to the top.
Each number should be written in a separate line 
without any superfluous characters such as leading or following spaces. Sample Input 5 2
3 1
3 1
10 3
1 10
10 1
8 3
0 0 Output for the Sample Input 4
4

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

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

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

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

    print(card[0])

Solution (Python):
while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break
    deck = [i + 1 for i in range(n)]
    for shuffle in range(r):
        p, c = map(int, input().split())
        
        hoge = deck[len(deck) - p - c + 1 : len(deck) - p + 1]
        del deck[len(deck) - p - c + 1 : len(deck) - p + 1]
        deck.extend(hoge)
        
    print(deck[-1])

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

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

while True:
    n,r = inpl()
    if n == 0:
        break
    else:
        yama = [n-i for i in range(n)]
        for _ in range(r):
            p,c = inpl()
            next_yama = yama[p-1:p-1+c] + yama[:p-1] + yama[p-1+c:]
            yama = next_yama
        print(yama[0])

Solution (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])

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

Solution (Python):


import heapq

while True:
    n,r = map(int,input().split(" "))
    if n==0 and r == 0:
        break
    q = []
    for i in range(n):
        heapq.heappush(q,(i,n-i))
    for i in range(r):
        p,c = map(int,input().split(" "))
        tmpQueue = []
        for j in range(p-1+c):
            tp = heapq.heappop(q)
            if j < p-1:
                heapq.heappush(tmpQueue,(j+c,tp[1]))
            else:
                heapq.heappush(tmpQueue,(j-p+1,tp[1]))
        for j in range(p-1+c):
            heapq.heappush(q,heapq.heappop(tmpQueue))
    print(heapq.heappop(q)[1])

Solution (Python):



(n, r) = map(int, raw_input().split())
while n!=0 and r!=0:
    list = [n-j for j in range(n)]
    for i in range(r):
        (p, c) = map(int, raw_input().split())
        p -= 1
        list = list[p:p+c] + list
        del list[p+c:p+c+c]

    print list[0]
    (n, r) = map(int, raw_input().split())

Solution (Python):
n,r  = map (int, raw_input().split(" "))
while (n,r) != (0,0) :
	deck = [n - i for i in range(n)]
	for i in range(r):
		p,c  = map (int, raw_input().split(" "))
		deck = deck[p-1:p-1+c] + deck[:p-1] + deck[p-1+c:]
	print deck[0]
	n,r  = map (int, raw_input().split(" "))

Solution (Python):


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

Solution (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])

Solution (Python):

import sys

def solve(n, r):
	fuda = [i for i in xrange(1,n+1)]
	fuda = fuda[::-1]
	for i in xrange(r):
		p,c = map(int,raw_input().split())
		fuda = fuda[p-1:p+c-1] + fuda[0:p-1] + fuda[p+c-1:n]
	print fuda[0]

if __name__ == "__main__":
	while 1:
		n,r = map(int,raw_input().split())
		if n == 0 and r == 0:
			sys.exit()
		else:
			solve(n,r)

Solution (Python):

while True:
	n, r = map(int, input().split())
	if (n, r) == (0, 0):
		break
	cards = list(range(1, n+1))[::-1]

	for i in range(r):
		p, c = map(int, input().split())
		cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]
	print(cards[0])

Solution (Python):
while True:
    n,r = map(int, raw_input().split())
    if n==0 and r==0:
        break
    else:
        list = []
        for i in range(1,n+1):
            list.append(i)
        
        for i in range(0,r):
            p, c = map(int, raw_input().split())
            hoge = list[len(list)-p+1:len(list)]
            del list[len(list)-p+1:len(list)]
            
            
            
            list[len(list)-c:len(list)-c] = hoge
            
        print list[len(list)-1]

Solution (Python):
while True:
    n, r = map(int, raw_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, raw_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])

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

    l = range(n, 0, -1)

    for i in range(r):
        tmp = []
        p, c = map(int, raw_input().split())
        for j in range(c):
            tmp.append(l.pop(p - 1))
        l = tmp + l
    print l[0]

Solution (Python):
while True:
    n, r = map(int, raw_input().split())
    if n == r == 0:
        break
    old = range(n, 0, -1)
    new = range(n, 0, -1)
    for shuffle in xrange(r):
        old = list(new)
        p, c = map(int, raw_input().split())
        if p >= 2:
            for i in xrange(c):
                new[i] = old[p-1+i]
            for i in xrange(p-1):
                new[c+i] = old[i]
    print new[0]

Solution (Python):
f = True
while f:
    x = map(int, raw_input().split())
    if x == [0, 0]:
        f = False
    else:
        deck = list(range(x[0]))
        deck.reverse()
        deck = map((lambda x: x + 1), deck)
        times = x[1]
        for i in range(times):
            p, c = tuple(map(int,raw_input().split()))
            deck = deck[p-1:p-1+c] + deck[0:p-1] + deck[p-1+c:]
        print deck[0]

Solution (Python):



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

Solution (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])

Solution (Python):
while True:
    n, r = map(int, input().split())

    if n == 0 and r == 0:
        break

    cards = list(range(1, n+1))[::-1]

    for _ in range(r):
        p, c = map(int, input().split())
        cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]

    print(cards[0])

Solution (Python):
while True:
  n,r = tuple(map(int,input().split()))
  if n==0 and r==0:
    break
  l = [n-i for i in range(n)]
  for i in range(r):
    p,c = tuple(map(int,input().split()))
    l1 = [l[i] for i in range(p-1,p+c-1)]
    l2 = [l[i] for i in range(0,p-1)]
    l3 = l1+l2
    for i in range(p+c-1):
      l[i] = l3[i]
  print(l[0])

Solution (Python):
while True:
	sousa=input().split()
	sousa=[int(sousa[0]),int(sousa[1])]
	if sousa==[0,0]:break
	yama=[]
	for k in range(sousa[0]):yama.append(k+1)
	yama=yama[::-1]
	for r in range(sousa[1]):
		[p,c]=input().split()
		[p,c]=[int(p),int(c)]
		yama[:p+c-1]=yama[p-1:p+c-1]+yama[:p-1]
	print(yama[0])

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

Solution (Python):

while True:
    num_cards, num_repeat = map(int, input().split())

    if num_cards == 0 and num_repeat == 0:
        break

    
    cards = list(range(num_cards, 0, -1))

    for _ in range(num_repeat):
        p, c = map(int, input().split())
        cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]

    print(cards[0])

Solution (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
        
        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

Solution (Python):
cards,trial = (int(n) for n in input().split(" "))
while True:
    cards = list(reversed([int(n) for n in range(1,(cards)+1)]))
    for n in range(trial):
        num,change = (int(n) for n in input().split(" "))
        num -= 1
        disp = cards[num:num+change]
        cards[change:change+num] = cards[:num]
        cards[:change] = disp
    print(cards[0])
    cards,trial = (int(n) for n in input().split(" "))
    if cards == 0 and trial == 0:
        break

Solution (Python):
n,r = map(int,input().split())

while n!=0 and r!=0:
	card = list(range(1,n+1))[::-1]
	for _ in range(r):
		p,c = map(int,input().split())
		pcard = card[0:p-1]
		ccard = card[p-1:p-1+c]
		tmp = card[p-1+c:]
		nxt = []
		nxt.extend(ccard)
		nxt.extend(pcard)
		nxt.extend(tmp)
		card = nxt
	print(card[0])
	n,r = map(int,input().split())

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

Solution (Python):
while True:
    N, R = map(int, raw_input().split())
    if N == R == 0:
        break
    A = range(N, 0, -1)
    for i in xrange(R):
        p, c = map(int, raw_input().split())
        A = A[p-1:p+c-1] + A[:p-1] + A[p+c-1:]
    print A[0]

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

Solution (Python):
while True:
    n,r = map(int,input().split())
    if n==r==0: break
    l = list(range(n,0,-1))
    for i 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])

Solution (Python):
while True:
    n,r = map(int,input().split())
    if n==r==0: break
    l = list(range(n,0,-1))
    for _ 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])

Solution (Python):
while True:
	x, y = map(int,raw_input().split())
	lst = range(x,0,-1)
	if x == 0 and y == 0:
		break
	lst = range(x,0,-1)	
	for i in range(y):
	    c = []
	    a,b = map(int,raw_input().split())
	    for f in range(b):
	    	c.append(lst.pop(a-1))
	    lst = c + lst
	print lst[0]

Solution (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])

Solution (Python):
while True:
    str = raw_input()
    list = str.split()
    n = int(list[0])
    r = int(list[1])
    if(n == 0 and r == 0):
        break
    n_list = []
    for i in xrange(n):
        n_list.append(i+1)
    for i in xrange(r):
        str = raw_input()
        list = str.split()
        p = int(list[0])
        c = int(list[1])
        n_list =  n_list[0:n-(p-1)-c] + n_list[n-(p-1):n] + n_list[n-(p-1)-c:n-(p-1)]
    print n_list[n-1]

Solution (Python):
while True:
    n,r = map(int,raw_input().split())
    if(n == 0 and r == 0):
        break
    n_list = []
    for i in xrange(n):
        n_list.append(i+1)
    for i in xrange(r):
        p,c = map(int, raw_input().split())
        n_list =  n_list[0:n-(p-1)-c] + n_list[n-(p-1):n] + n_list[n-(p-1)-c:n-(p-1)]
    print n_list[n-1]

Solution (Python):
while 1:
    n,r=map(int,input().split())
    if n==0: break
    c=list(range(n,0,-1))
    for _ in range(r):
        a,b=map(int,input().split())
        c=c[a-1:a+b-1]+c[:a-1]+c[a+b-1:]
    print(c[0])

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

Solution (Python):
import sys

while 1:
    n, r = map(int, sys.stdin.readline().split())

    if (n, r) == (0, 0):
        break

    yama = [int(n - i) for i in range(n)]

    for lp in range(r):
        p, c = map(int, sys.stdin.readline().split())
        p -= 1
        yama = yama[p:p + c] + yama[:p] + yama[p + c:]

    print(yama[0])

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

Solution (Python):
while True:
    n,r = map(int,raw_input().split())
    if(n == 0 and r == 0):
        break
    li = []
    for i in xrange(1,n+1):
        li.append(i)
    for i in xrange(r):
        temp_lis1 = []
        p,c = map(int,raw_input().split())
        if(c == 1):
            temp_lis1.append(li[n-p])
            del(li[n-p])
        else:
            temp_lis1.extend(li[n-p-c+1:n-p+1])
            del(li[n-p-c+1:n-p+1])
        li.extend(temp_lis1)
    print li[n-1]

Solution (Python):
while True:
    n,r = map(int,raw_input().split())
    if(n == 0 and r == 0):
        break
    li = []
    for i in xrange(1,n+1):
        li.append(i)
    for i in xrange(r):
        temp_lis1 = []
        p,c = map(int,raw_input().split())
        if(c == 1):
            temp_lis1.append(li[n-p])
            del(li[n-p])
        else:
            temp_lis1.extend(li[n-p-c+1:n-p+1])
            del(li[n-p-c+1:n-p+1])
        li.extend(temp_lis1)
    print li[n-1]

Solution (Python):
while True:
    n, r = map(int, input().split())
    if n == 0:
        break
    cards = [i+1 for i in range(n)][::-1]
    for _ 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])

Solution (Python):
while True:
    a=[int(num)for num in input().split(' ')]
    n=a[0]
    if n==0:break
    hanafuda=[i+1 for i in range(n)]
    for i in range(a[1]):
        b=[int(num)for num in input().split(' ')]
        for j in range(b[1]):hanafuda.append(hanafuda.pop(n-(b[0]+b[1])+1))
    print(hanafuda.pop())

Solution (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])

Solution (Python):
while 1:
    count, times = [int(a) for a in input().split()]
    hanahuda = [i+1 for i in range(count)]
    if count == times == 0:break
    for i in [0]*times:
        p,c = [int(i) for i in input().split()]
        for i in [0]*c:hanahuda.append(hanahuda.pop(count-(p+c)+1))
    print(hanahuda.pop())

Solution (Python):
def solve_testcase():
    n, r = map(int, raw_input().split())
    if (n, r) == (0, 0):
        return 1

    cards = range(n, 0, -1)
    for i in range(r):
        p, c = map(int, raw_input().split())
        cards[:c], cards[c:p+c] = cards[p-1:p+c], cards[:p-1]

    print cards[0]
    return 0

def main():
    while not solve_testcase():
        pass

if __name__ == '__main__':
    main()

Solution (Python):

N,r=(int(i) for i in input().split())
while N!=0 or r!=0:
    H=[int(N-i) for i in range(N)]
    for i in range(r):
        p,c=(int(i) for i in input().split())
        T=[]
 
        for j in range(p-1,p+c-1):
  
            T.append(H[p-1])
            H.pop(p-1)
        H=T+H
    print(H[0])
    N,r=(int(i) for i in input().split())

Solution (Python):
if __name__ == "__main__":
    while True:
        n,r=list(map(int,input().strip().split()))
        if n == 0 and r ==0 :break
        cards = [i for i in range(1,n + 1)]
        pset = []
        cset = []
        for j in range(r):
            p,c = list(map(int,input().strip().split()))
            pset = cards[n-(p - 1):]
            cset = cards[n-c-(p-1):n-(p-1)]
            other = cards[:n-c-(p-1)]
            cards = other + pset + cset
        print(cards[n-1])

Solution (Python):
while True:
    n,r=[int(s)for s in input().split(" ")]
    if n==r==0:break
    ops=[[int(s)for s in input().split(" ")]for i in range(r)]
    cd=[n-i for i in range(n)]
    for op in ops:
        p,c=op
        l=cd[p-1:p+c-1]
        del cd[p-1:p+c-1]
        cd=l+cd
    print(cd[0])

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

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

Solution (Python):
while True:
    n, r = list(map(lambda x: int(x), input().split(" ")))
    if n == 0 and r == 0:
        break
    cards = [i for i in range(1,n+1)]
    cards = cards[::-1]

    for i in range(r):
        p, c = list(map(lambda x: int(x), input().split(" ")))
        p -= 1
        cards = cards[p:p+c] + cards[0:p] + cards[p+c:]
    
    print(cards[0])

Solution (Python):
while True:
	l = input()
	L = l.split()
	for i in range(len(L)):
		L[i] = int(L[i])
	if L[0] == 0:
		break	
	a = [L[0]-number for number in range(L[0])]
	for j in range(L[1]):
		r = input()
		R = r.split()
		for k in range(len(R)):
			R[k] = int(R[k])
		b = []
		b += a[R[0]-1:R[0]+R[1]-1]
		b += a[:R[0]-1]
		b += a[R[0]+R[1]-1:]
		a.clear()
		a = b.copy()
	print(a[0])

Solution (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()

Solution (Python):
while True:
    n, r = map(int, raw_input().split())

    if n == 0 and r == 0:
        break

    Cards = [i for i in range(n, 0, -1)]

    for i in range(r):
        p, c = map(int, raw_input().split())
        Cards = Cards[p-1:p-1+c] + Cards[:p-1] + Cards[p-1+c:]

    print Cards[0]

Solution (Python):
while True:
    n, r = map(int, raw_input().split())

    if n == 0 and r == 0:
        break

    Cards = range(n, 0, -1)

    for i in range(r):
        p, c = map(int, raw_input().split())
        Cards = Cards[p-1:p-1+c] + Cards[:p-1] + Cards[p-1+c:]

    print Cards[0]

Solution (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

Solution (Python):
while True:
    n, r = map(int, input().split())
    if n == 0:
        break
    else:
        cards = list(reversed(range(n)))
        for _ in range(r):
            p, c = map(int, input().split())
            for i,x in enumerate(cards):
                if 0 <= x < p-1:
                    cards[i] += c
                elif p-1 <= x < p-1+c:
                    cards[i] -= p-1
                else:
                    pass
        for i,x in enumerate(cards):
            if x == 0:
                print(i+1)

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

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

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

Solution (Python):
def main():
    ans = []
    while True:
        n, r = map(int, input().split())
        if n == 0 and r == 0:
            break
        cards = []
        for i in range(n):
            cards.append(i+1)
        cards = cards[::-1]
        for i in range(r):
            p, c = map(int, input().split())
            cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]
        ans.append(cards[0])

    for i in range(len(ans)):
        print(ans[i])

main()

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

    ope = [list(map(int, input().split())) for _ in range(r)]
    d = [n-i for i in range(n)]

    for i in range(r):
        tv = d[ope[i][0]-1:ope[i][0]-1+ope[i][1]]
        to = d[:ope[i][0]-1] + d[ope[i][0]-1+ope[i][1]:]
        d = tv + to
    print(d[0])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n,r = LI()
        if n == 0:
            break
        a = list(range(n))
        for _ in range(r):
            p,c = LI()
            a = a[p-1:p-1+c] + a[:p-1] + a[p-1+c:]
        rr.append(n - a[0])

    return '\n'.join(map(str, rr))


print(main())

Solution (Python):
while True:
    n, r = [int(s) for s in input().strip().split()]

    if n == 0 and r == 0:
        break

    cards = list(range(1, n+1))
    cards.reverse()

    for _ in range(r):
        p, c = [int(s) for s in input().strip().split()]

        part1 = cards[0:p-1]
        part2 = cards[p-1:p-1+c]

        cards[0:c] = part2
        cards[c:c+p-1] = part1

    print(cards[0])

Solution (Python):
n , r = map(int, input().split())
while(n != 0 or r != 0):
    deck = []
    for i in range(n):
        deck.append(i+1)
    deck.reverse()
    for i in range(r):
        p, c = map(int, input().split())
        deck[:p + c -1] = deck[p-1:p+c-1] + deck[:p-1]
    print(deck[0])
    n , r = map(int, input().split())

Solution (Python):
while 1:
  n,r=list(map(int,input().split()))
  if not n and not r:break
  l=list(range(1,n+1))[::-1]
  for _ in range(r):
    p,c=list(map(int,input().split()))
    l=l[p-1:p-1+c]+l[0:p-1]+l[p-1+c:]
  print(l[0])

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

Solution (Python):
n=1
r=1
while n !=0 and r!=0:
    n,r=input().split()
    n,r=int(n),int(r)

    card= [[int(i) for i in input().split()] for i in range(r)]
    yama= list(range(n,0,-1))
    
    if n ==0 and r==0:
        break

    for i in range(r):
        p=card[i][0]
        c=card[i][1]
        x=yama[:p-1]
        y=yama[p-1:p-1+c]
        z=yama[p-1+c:] 
      
       
        yama=(y+x+z)
        
    print(yama[0])

Solution (Python):
while 1:
        n,r = map(int, raw_input().split())
        if n == 0 and r == 0: break
        lib = range(n, 0, -1)
        
        for i in xrange(r):
                temp = []
                p,c = map(int, raw_input().split())
                for j in xrange(c):
                        temp.append(lib.pop(p-1))
                lib = temp + lib
                
        print lib[0]

Solution (Python):
import sys


while True:
    n, r = map(int, sys.stdin.readline().split())
    if n == 0 and r == 0:
        break
    shuffle = []
    for i in xrange(r):
        shuffle.append(map(int, sys.stdin.readline().split()))
    shuffle.reverse()
    pile = range(n)
    for s in shuffle:
        pile[s[0] + s[1] - 1:s[0] + s[1] - 1] += pile[:s[1]]
        pile = pile[s[1]:]

    print len(pile) - pile.index(0)

"""10 9 8 7 6 5 4 3 2 1
1 10 9 8 7 6 5 4 3 2
4 3 2 1 10 9 8 7 6 5

0 1 2 3 4 5 6 7 8 9
3 4 5 6 7 8 9 0 1 2
4 5 6 7 8 9 0 1 2 3

5 4 3 2 1
3 5 4 2 1
4 3 5 2 1

0 1 2 3 4
1 2 0 3 4
2 0 1 3 4"""

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

Solution (Python):
while 1:
	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())
		card = card[p-1:p-1+c] + card[:p-1] + card[p-1+c:]
	print card[0]

Solution (Python):

def shuffle(cards):
    index,cut_num = map(int,input().split()) 
    pop = cards[index-1 :index + cut_num-1 ]
    del cards[index-1:index + cut_num-1]
    return pop + cards 

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

  cards = list(reversed(range(1,num_card+1)))
  for i in range(challange):
      cards = shuffle(cards)
  print(cards[0])

Solution (Python):
import sys
import math
input = sys.stdin.readline

n, r = input().rstrip().split()
n, r = int(n), int(r)
while n + r > 0:
    yama = list(range(1, n + 1))[::-1]
    for _ in range(r):
        p, c = input().rstrip().split()
        p, c = int(p), int(c)
        top = yama[:p - 1]
        mid = yama[p - 1:p - 1 + c]
        yama[:c] = mid
        yama[c:p - 1 + c] = top
    print(yama[0])
    n, r = input().rstrip().split()
    n, r = int(n), int(r)

Solution (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])

Solution (Python):

def create_deck(deck_size):
    deck = []
    for i in range(0,deck_size):
        deck.append(i+1)
    return deck

def shuffle_deck(deck, start, cut_size):
    after = []
    cut_cards = []
    b = len(deck) - cut_size - start
    for i in range(0,len(deck)):
        if b >= i:
            after.append(deck[i])
            continue
        if (b+cut_size) >= i:
            cut_cards.append(deck[i])
            continue
        after.append(deck[i])
    after.extend(cut_cards)
    return after

while True:
    data = input().split()
    deck_size, shuffle_count = int(data[0]),int(data[1])
    if deck_size == shuffle_count == 0: break
    deck = create_deck(deck_size)
    for i in range(0,shuffle_count):
        cut_info = data = input().split()
        start, cut_size = int(cut_info[0]),int(cut_info[1])
        deck = shuffle_deck(deck, start, cut_size)
    print(deck[len(deck)-1])