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 = map(int, input().split())
    if n == 0:
        break
    cards = list(range(n, 0, -1))
    for p, c in (map(int, input().split()) for _ in [0]*r):
        cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]

    print(cards[0])

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

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

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)

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

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-
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(" "))
        for j in range(p-1+c):
            tp = heapq.heappop(q)
            if j < p:
                heapq.heappush(q,(j+p-1,tp[1]))
            else:
                heapq.heappush(q,(j-p,tp[1]))
    print(heapq.heappop(q)[1])

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

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

Python: MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    while True:
        n,r = map(int,input().split())
        if n == 0:
            return
        ans = list(range(n,0,-1))
        for _ in range(r):
            p,c = map(int,input().split())
            p -= 1
            ans = ans[p:p + c] + ans[:p] + ans[p + c:]
        print(ans[0])
if __name__ == '__main__':
    main()

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

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

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

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)

    print(card[0])

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

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

    print(cs[-1] + 1)

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

Python: # coding: utf-8
def q0():
    while True:
        data=[]
        n=int(input())
        if n==0:
            return
        for i in range(n):
            data.append(int(input()))
        print((sum(data)-max(data)-min(data))//(n-2))

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


question=[q0,q1]

question[1]()

Python: while True:
  n,r=map(int,input().split())
  if n==0 and r==0:
    break
  yama=[i for i in range(1,n+1)]
  for i in range(r):
    p,c=map(int,input().split())
    yama1=[]
    for i in range(n-(p-1)-c,n-(p-1)):
      a=yama[i]
      yama1.append(a)
    #print(yama1)
    for i in range(len(yama1)):
      if yama1[i] in yama:
        yama.remove(yama1[i])
    yama=yama+yama1
    #print(yama)
  print(yama[n-1])

Python: l = input()
L = l.split()
for i in range(len(L)):
	L[i] = int(L[i])
while True:
	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])

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