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

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

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

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)
    next = input().split()
    n, r = list(map(int,next))

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

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

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+c:]

    print(cards[0])

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

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

Python: # encoding: utf-8
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])

Python: def main():
    while True:
        n, r = map(int, input().split())
        if n == 0:
            break
        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])
main()

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

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

    inds = [i for i in reversed(range(1, n+1))]

    for i in range(r):
        p, c = map(lambda j: int(j), input().split())
        inds = inds[p-1:p-1+c] + inds[:p-1] + inds[p-1+c:]

    print(inds[0])

Python: res = []
while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    card = [i for i in range(n,0,-1)]
    for i in range(k):
        p,c = map(int,input().split())
        card = card[p-1:p-1+c]+card[:p-1]+card[p+c-1:]
    res.append(card[0])
for i in range(len(res)):
    print(res[i])

Python: # -*- coding: utf-8 -*-

def main():
    while 1:
        n, r = list(map(int,input().split()))
        l = list(range(n, 0, -1))
        if n == 0 and r == 0:
            return 0
        for _ in range(r):
            p, c = list(map(int, input().split()))
            l_ = l[p-1:p+c-1]
            l_.extend(l[:p-1])
            l_.extend(l[p+c-1:])
            l = l_
        print(l[0])


if __name__ == "__main__":
    main()

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

Python: import copy 
def solve():
  while(True):
    n, r = map(int, input().split())
    beforelist = [i for i in range(n, 0, -1)]
    afterlist = copy.deepcopy(beforelist)
    #print(beforelist)
    #print(afterlist)
    if n == 0 and r == 0:
        break
    for _ in range(r):
        p, c = map(int, input().split())
        j = 0
        for i in range(p-1,p-1+c):
            #print(beforelist)
            afterlist[j] = copy.deepcopy(beforelist[i])
            j+=1
            #print(afterlist)
            #print(beforelist)
        for i in range(0,p-1):
            afterlist[j] = copy.deepcopy(beforelist[i])
            j+=1
        beforelist = copy.deepcopy(afterlist)
        #print(afterlist)
    print(beforelist[0])
if __name__ == '__main__':
  solve()

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