Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
def gcd(x,y):
    a = x % y
    y_ans = []
    two_ans = []
    for i in range(1,y + 1):
        if y % i == 0:
            y_ans.append(i)
    for i in range(1,a + 1):
        if a % i == 0:
            two_ans.append(i)
    yset = set(y_ans)
    twoset = set(two_ans)
    matched = list(yset & twoset)
    print max(matched) 

n = map(int, raw_input().split())
gcd(n[0],n[1])

Fixed submission:
# coding:utf-8
def gcd(a,b):
    while b:
        a, b = b, a % b
    return a
n = map(int, raw_input().split())
n.sort(reverse=True)
print gcd(n[0],n[1])

Buggy python submission (verdict: Runtime Error):
# coding:utf-8
def gcd(x,y):
    a = x % y
    y_ans = []
    two_ans = []
    for i in range(1,y + 1):
        if y % i == 0:
            y_ans.append(i)
    for i in range(1,a + 1):
        if a % i == 0:
            two_ans.append(i)
    yset = set(y_ans)
    twoset = set(two_ans)
    matched = list(yset & twoset)
    print max(matched) 

n = map(int, raw_input().split())
gcd(n[0],n[1])

Fixed submission:
# coding:utf-8
def gcd(a,b):
    while b:
        a, b = b, a % b
    return a
n = map(int, raw_input().split())
n.sort(reverse=True)
print gcd(n[0],n[1])

Buggy python submission (verdict: Runtime Error):
# coding:utf-8
def gcd(x,y):
    if x == y:
        print x
        return
    else if x < y:
        t = x
        x = y
        y = t
    a = x % y
    y_ans = []
    two_ans = []
    for i in range(1,y + 1):
        if y % i == 0:
            y_ans.append(i)
    for i in range(1,a + 1):
        if a % i == 0:
            two_ans.append(i)
    yset = set(y_ans)
    twoset = set(two_ans)
    matched = list(yset & twoset)
    print max(matched) 

n = map(int, raw_input().split())
gcd(n[0],n[1])

Fixed submission:
# coding:utf-8
def gcd(a,b):
    while b:
        a, b = b, a % b
    return a
n = map(int, raw_input().split())
n.sort(reverse=True)
print gcd(n[0],n[1])
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
import math
array = map(int,raw_input().split())
x1 = array[0]
y1 = array[1]
x2 = array[2]
y2 = array[3]
answer = math.sqrt(math.pow(x2 - x1,2) + math.pow(y2 - y1,2))
print answer



Fixed submission:
# coding:utf-8
import math
array = map(float,raw_input().split())
x1 = array[0]
y1 = array[1]
x2 = array[2]
y2 = array[3]
answer = math.sqrt(math.pow(x2 - x1,2) + math.pow(y2 - y1,2))
print answer
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
while True:
    line = raw_input().split()
    a = int(line[0])
    op = line[1]
    b = int(line[2])
    answer = 0
    if op == '+':
        answer = a + b
    elif op == '-':
        answer = a - b
    elif op == '*':
        answer = a * b
    elif op == '/':
        answer = a / b
    elif op == '?' and a == 0 and b == 0:
        break
    print "%d" % answer

Fixed submission:
# coding:utf-8
while True:
    line = raw_input().split()
    a = int(line[0])
    op = line[1]
    b = int(line[2])
    answer = 0
    if op == '+':
        answer = a + b
    elif op == '-':
        answer = a - b
    elif op == '*':
        answer = a * b
    elif op == '/':
        answer = a / b
    elif op == '?':
        break
    print "%d" % answer
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
import sys
n = input()
array = []
for i in range(n):
    array.append(map(int, raw_input().split()))
array.sort()
result = [[]]
index = 0
for i in range(1,n):
    if(array[i - 1][0:3] == array[i][0:3]):
        if(result[index][3]):
            result[index][3] += array[i][3:]
        else:
            result[index][0:3] = array[i][0:3]
            result[index][3] = array[i][3:]
    else:
        index += 1
for i in range(4):
    for j in range(3):
        for k in range(10):
            sys.stdout.write(' ')
            if(i == array[j][0] - 1 and k == array[j][2] - 1):
                print array[j][3],
            else:
                print 0,
        else:
            print
    else:
        if(i != 3):
            print "####################"



Fixed submission:
# coding:utf-8
import sys
n = input()
array = []
for i in range(n):
    array.append(map(int, raw_input().split()))
array.sort()
result = [[0 for i in range(4)] for j in range(n)]
index = 0
result[index] = array[0][0:4]
for i in range(1,n):
    if result[index][0:3] == array[i][0:3]:
        result[index][3] += array[i][3]
    elif result[index][0:3] != array[i][0:3]:
        index += 1
        result[index] = array[i][0:]
index = 0
for i in range(4):
    for j in range(3):
        for k in range(10):
            sys.stdout.write(' ')
            if(i == result[index][0] - 1 and j == result[index][1] - 1 and k == result[index][2] - 1):
                print result[index][3],
                if index != len(result) - 1:
                    index += 1
            else:
                print 0,
        else:
            print
    else:
        if(i != 3):
            print "####################"
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
a = list(raw_input().split().lower())
dict = {}
for i in range(26):
    dict[chr(ord('a')+i)] = 0
for i in a:
    for key,value in dict.items():
        if key == i:
            dict[key] += 1
for key,value in sorted(dict.items()):
    print "%s : %d" % (key,value)



Fixed submission:
# coding:utf-8
import sys
a = []
for line in sys.stdin:
    a.append(list(line.strip().replace(" ","").lower()))
a = reduce(lambda x,y: x+y,a)
dict = {}
for i in range(26):
    dict[chr(ord('a')+i)] = 0
for i in a:
    for key,value in dict.items():
        if key == i:
            dict[key] += 1
for key,value in sorted(dict.items()):
    print "%s : %d" % (key,value)
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
W = raw_input().lower()
array = []
cnt = 0
while True:
    line = raw_input()
    if line == "END_OF_TEXT"
        break
    split = line.lower().split()
    for s in split:
        array.append(s)
for word in array:
    if W == word:
        cnt += 1
print cnt



Fixed submission:
# coding:utf-8
W = raw_input().lower()
array = []
cnt = 0
while True:
    line = raw_input()
    if line == "END_OF_TEXT":
        break
    split = line.lower().split()
    for s in split:
        array.append(s)
for word in array:
    if W == word:
        cnt += 1
print cnt
Buggy python submission (verdict: Runtime Error):
White True:
    x = input()
    print x**3

Fixed submission:
x = input()
print x**3

Buggy python submission (verdict: Runtime Error):
white True:
    x = input()
    print x**3

Fixed submission:
x = input()
print x**3
Buggy python submission (verdict: Time Limit Exceeded):
import math
    
def isprime(x):
    p = [2]
    if x == 2:
        return True
    if x == 3:
        return True
    if max(p) < x**0.5:
        for j in range(max(p), math.floor(x**0.5) + 1):
            if all([j % k != 0 for k in p]):
                p.append(j)
    i = 0
    while i <= len(p)-1:
        if p[i] > x**0.5:
            return False
        if x%p[i] == 0:
            return False
        i += 1
    return True


n = int(input())
res = 0
for i in range(n):
    k = int(input())
    if isprime(k):
        res += 1
print(res)

Fixed submission:
import math

p = [2]
    
def isprime(x):
    if x == 2:
        return True
    if x == 3:
        return True
    if max(p) < x**0.5:
        for j in range(max(p), math.floor(x**0.5) + 1):
            if all([j % k != 0 for k in p]):
                p.append(j)
    i = 0
    while i <= len(p)-1:
        if x%p[i] == 0:
            return False
        if p[i] > x**0.5:
            break;
        i += 1
    return True


n = int(input())
res = 0
for i in range(n):
    k = int(input())
    if isprime(k):
        res += 1
print(res)

Buggy python submission (verdict: Runtime Error):
import math

p = [2]
    
def isprime(x):
    if x == 2:
        return True
    if x == 3:
        return True
    if max(p) < x**0.5:
        for j in range(max(p), math.floor(x**0.5) + 1):
            if all([j % k != 0 for k in p]):
                p.append(j)
    i = 0
    while i <= len(p)-1:
        if x%p[i] == 0:
            return False
        if p[i] > x**0.5:
            break;
        i += 1
    return True


n = int(input())
res = 0
for i in range(n):
    k = int(input())
    if isprime(k):
        res += 1
print(res, p)

for i in range(n):
    k = int(input())
    if isprime(k):
        res += 1
print(res)

Fixed submission:
import math

p = [2]
    
def isprime(x):
    if x == 2:
        return True
    if x == 3:
        return True
    if max(p) < x**0.5:
        for j in range(max(p), math.floor(x**0.5) + 1):
            if all([j % k != 0 for k in p]):
                p.append(j)
    i = 0
    while i <= len(p)-1:
        if x%p[i] == 0:
            return False
        if p[i] > x**0.5:
            break;
        i += 1
    return True


n = int(input())
res = 0
for i in range(n):
    k = int(input())
    if isprime(k):
        res += 1
print(res)
Buggy python submission (verdict: Runtime Error):
l = list(map(int, input().split()))
l.sort()
print(" ".join(l))

Fixed submission:
l = list(map(int, input().split()))
l.sort()
print(l[0], l[1], l[2])

Buggy python submission (verdict: Runtime Error):
l = list(map(int, input().split()))
l.sort()
print(l[0], l[1], l[[2])

Fixed submission:
l = list(map(int, input().split()))
l.sort()
print(l[0], l[1], l[2])
Buggy python submission (verdict: Runtime Error):
N = 300000
a = [((i % 7 ==1)or(i % 7 ==6)) for i in range(N)]
#print(a[11])
a[1]=0
p =[]
for i in range(6,N):
    if a[i]:
        p+=[i]
        for j in range(i * i ,N,i):
            a[j] = 0
 
while True:
    n = int(input())
    if n == 1:
        break
    print(n,end = ":")
    for x in p:
        if n % x ==0:
            print(" "+str(x),end = " ")

    print()



Fixed submission:
N = 300000
a = [((i % 7 ==1)or(i % 7 ==6)) for i in range(N)]
#print(a[11])
a[1]=0
p =[]
for i in range(6,N):
    if a[i]:
        p+=[i]
        for j in range(i * i ,N,i):
            a[j] = 0
 
while True:
    n = int(input())
    if n == 1:
        break
    print(n,end = ":")
    for x in p:
        if n % x ==0:
            print(" "+str(x),end = "") 

    print()
Buggy python submission (verdict: Runtime Error):
N = int(input())

t = [0 for i in range(100001)]

for i in range(N):
    a,b = [int(i) for i in input().split(' ')]
    t[a-1] +=1
    t[b] -= 1

ans = 0

for i in range(1,100001):
    t[i] += t[i-1]
    if (t[i] > i):
        ans = i

print(ans)



Fixed submission:
N = int(input())

t = [0 for i in range(100002)]

for i in range(N):
    a,b = [int(i) for i in input().split(' ')]
    t[a-1] +=1
    t[b] -= 1

ans = 0
#print(t)
for i in range(1,100002):
    t[i] += t[i-1]
    if (t[i] >= i):
        ans = i
#print(t)
print(ans)
Buggy python submission (verdict: Runtime Error):
Q = int(input())

def solve(x,ans):
    X = str(x)
    if len(X) == 1:
        print(ans)
        return
    ret= 0
    for i in range(1,len(X)):
        n = int(X[i:]) * int(X[:i])
        ret = max(ans,n)
        
    #print(ret)
    return solve(ret,ans + 1)

for i in range(Q):
    solve(int(input()),0)



Fixed submission:
Q = int(input())

def solve(x,ans):
    #X = str(x)
#    print(x,ans)
    if len(x) == 1:
        print(ans)
        return
    ret= 0
    for i in range(1,len(x)):
        n = int(x[i:]) * int(x[:i])
        ret = max(ret , n)
        
    #print(ret)
    return solve(str(ret),ans + 1)

for i in range(Q):
    solve(input(),0)

Buggy python submission (verdict: Runtime Error):
Q = int(input())

def solve(x,ans):
    X = str(x)
    if len(X) == 1:
        print(ans)
        return
    ret= 0
    for i in range(1,len(X)):
        n = int(X[i:]) * int(X[:i])
        ret = max(ans,n)
        
    #print(ret)
    return solve(ret,ans + 1)

for i in range(Q):
    solve(int(input()),0)



Fixed submission:
Q = int(input())

def solve(x,ans):
    #X = str(x)
#    print(x,ans)
    if len(x) == 1:
        print(ans)
        return
    ret= 0
    for i in range(1,len(x)):
        n = int(x[i:]) * int(x[:i])
        ret = max(ret , n)
        
    #print(ret)
    return solve(str(ret),ans + 1)

for i in range(Q):
    solve(input(),0)
Buggy python submission (verdict: Runtime Error):
def solve(s):
    if len(s) ==3:
        if s[0]=='A' and s[1]=='B' and s[2]=='C':
            return True
        else:
            return False
    i=0
    a = 0
    b = 0
    c = 0
    lis =[]
    while i < len(s):
        if i+2<len(s) and s[i] =='A' and s[i+1] == 'B' and s[i+2] == 'C':
            lis.append('X')
            i += 3
        else:
            lis.append(s[i])
            if s[i] == 'A':
                a = 1
            if s[i] == 'B':
                b = 1
            if s[i] == 'C':
                c = 1
            i += 1

    if not(a+b+c == 2):
        return False
    if a==0:
        for i in range(len(lis)):
            if lis[i] == 'X':
                lis[i]='A'
    if b==0:
        for i in range(len(lis)):
            if lis[i] == 'X':
                lis[i]='B'
    if c==0:
        for i in range(len(lis)):
            if lis[i] == 'X':
                lis[i]='C'
    if len(s) == len(lis):
        return False

    return solve(lis)


if solve(input()):
    print("Yes")
else:
    print("No")



Fixed submission:
import sys
sys.setrecursionlimit(5010)

def solve(s): 
    if len(s) ==3:
        if s[0]=='A' and s[1]=='B' and s[2]=='C':
            return True
        else:
            return False
    i=0
    a = 0
    b = 0
    c = 0
    lis =[]
    while i < len(s):
        if i+2<len(s) and s[i] =='A' and s[i+1] == 'B' and s[i+2] == 'C':
            lis.append('X')
            i += 3
        else:
            lis.append(s[i])
            if s[i] == 'A':
                a = 1
            if s[i] == 'B':
                b = 1
            if s[i] == 'C':
                c = 1
            i += 1

    if not(a+b+c == 2):
        return False
    if a==0:
        for i in range(len(lis)):
            if lis[i] == 'X':
                lis[i]='A'
    if b==0:
        for i in range(len(lis)):
            if lis[i] == 'X':
                lis[i]='B'
    if c==0:
        for i in range(len(lis)):
            if lis[i] == 'X':
                lis[i]='C'
    if len(s) == len(lis):
        return False

    return solve(lis)


if solve(input()):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
x = input()

print(x * x * x)


Fixed submission:
x = int(input())
print(x ** 3)

Buggy python submission (verdict: Runtime Error):

x = input()
print(x ** 3)


Fixed submission:

x = int(input())
print(x*x*x)

Buggy python submission (verdict: Runtime Error):

x = input()
print(x ** 3)


Fixed submission:

x = int(input())
print(x*x*x)

Buggy python submission (verdict: Runtime Error):

x = input()
y = x ** 3
print(y)


Fixed submission:

x = int(input())
print(x*x*x)
Buggy python submission (verdict: Runtime Error):

a = input()
b = input()
print(a * b+ +(a + b) * 2)


Fixed submission:

a,b =(int(x) for x in input().split())
print(a * b, (a+b) * 2)

Buggy python submission (verdict: Runtime Error):

a = input()
b = input()
print(int(a) * int(b)+ +(int(a) + int(b)) * 2)


Fixed submission:

a,b =(int(x) for x in input().split())
print(a * b, (a+b) * 2)

Buggy python submission (verdict: Runtime Error):

a = input()
b = input()
print(int(a) * int(b) (int(a) + int(b)) * 2)


Fixed submission:

a,b =(int(x) for x in input().split())
print(a * b, (a+b) * 2)

Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
print(int(a) * int(b))
print((int(a) * int(b)) * 2)


Fixed submission:

a,b =(int(x) for x in input().split())
print(a * b, (a+b) * 2)

Buggy python submission (verdict: Runtime Error):

a = input()
b = input()
print(int(a) * int(b))
print((int(a) + int(b)) * 2)


Fixed submission:

a,b =(int(x) for x in input().split())
print(a * b, (a+b) * 2)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input(),split())
print(a * b,(a + b) * 2)




Fixed submission:

a,b =(int(x) for x in input().split())
print(a * b, (a+b) * 2)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input(),split())
print(a * b,(a + b) * 2)


Fixed submission:

a,b =(int(x) for x in input().split())
print(a * b, (a+b) * 2)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input(),split())
print(a * b,(a + b) * 2)


Fixed submission:

a,b =(int(x) for x in input().split())
print(a * b, (a+b) * 2)
Buggy python submission (verdict: Runtime Error):
import math

def main():
    f = true
    r = []
    while f:
        n = int(input())
        if n == 0:
            break
        m = []
        for i in range(n):
            m.append(int(input()))
        r.append(math.floor((sum(m) - max(m) - min(m)/(n-2)))
    res = ''
    for j in r:
        res += str(j)
    print(j)


Fixed submission:
import math

def main():
    r = []
    while True:
        n = int(input())
        if n == 0:
            break
        m = []
        for i in range(n):
            m.append(int(input()))
        r.append(math.floor((sum(m) - max(m) - min(m))/(n-2)))
    for j in r:
        print(j)

main()

Buggy python submission (verdict: Runtime Error):
import math

def main():
    f = true
    r = []
    while f:
        n = int(input())
        if n == 0:
            break
        m = []
        for i in range(n):
            m.append(int(input()))
        r.append(math.floor((sum(m) - max(m) - min(m)/(n-2))))
    res = ''
    for j in r:
        res += str(j)
    print(j)
    
main()


Fixed submission:
import math

def main():
    r = []
    while True:
        n = int(input())
        if n == 0:
            break
        m = []
        for i in range(n):
            m.append(int(input()))
        r.append(math.floor((sum(m) - max(m) - min(m))/(n-2)))
    for j in r:
        print(j)

main()
Buggy python submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-
#ICPC得点集計ソフトウェア
import sys
def solve(n):
	nums = []
	for i in xrange(n):
		temp = input()
		nums.append(temp)
	nums.sort()
	sum = 0
	for i in xrange(1,n-1):
		sum += nums[i]
	return sum / (n-2)


if __name__ == "__main__":
	while :
		N = input()
		if N == 0:
			sys.exit()
		else:
			print solve(N)

Fixed submission:
# -*- coding:utf-8 -*-
#ICPC得点集計ソフトウェア
import sys
def solve(n):
	nums = []
	for i in xrange(n):
		temp = input()
		nums.append(temp)
	nums.sort()
	sum = 0
	for i in xrange(1,n-1):
		sum += nums[i]
	return sum / (n-2)


if __name__ == "__main__":
	while 1:
		N = input()
		if N == 0:
			sys.exit()
		else:
			print solve(N)
Buggy python submission (verdict: Runtime Error):
import collections
cnt1=collections.Counter()
cnt2=collections.Counter()
n,m=map(int, input().split())
ll=[0]*1500
for i in range(n):
    x=int(input())
    for j in range(i):
        ll[j]+=x
        cnt1[ll[j]]+=1

for i in range(m):
    x=int(input())
    for j in range(i):
        ll[j]+=x
        cnt2[ll[j]]+=1
sets=set(cnt1.keys().cnt2.keys())
ans=0
for s in sets:
    ans+=cnt1[s]*cnt2[s]
print(s)

Fixed submission:
import collections
while 1:
    cnt1=collections.Counter()
    cnt2=collections.Counter()
    n,m=map(int, input().split())
    if n+m==0:
        break
    ll=[0]*1500
    for i in range(n):
        x=int(input())
        for j in range(i+1):
            ll[j]+=x
            cnt1[ll[j]]+=1
    ll=[0]*1500
    for i in range(m):
        x=int(input())
        for j in range(i+1):
           ll[j]+=x
           cnt2[ll[j]]+=1
    sets=set(cnt1.keys()&(cnt2.keys()))
    ans=0
    for s in sets:
        ans+=cnt1[s]*cnt2[s]
    print(ans)
Buggy python submission (verdict: Runtime Error):
a=int(input)
b=a%3600
c=a//3600
d=b%60
e=b//60
print(c,":",e,":",d)

Fixed submission:
a=int(input())
b=a%3600
c=a//3600
d=b%60
e=b//60
print(str(c)+":"+str(e)+":"+str(d))
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a<b:
    if b<c:
        print "Yes"
        sys.exit()
print("No")

Fixed submission:
import sys
#a,b=map(int,input().split())
a,b,c=map(int,input().split())
if a<b:
    if b<c:
        print("Yes")
        sys.exit()
print("No")
Buggy python submission (verdict: Runtime Error):
import sys
for i in range(10000):
 j=int(input)
 if j==0:
  sys.exit()
 print("Case",str(i)+":",j)

Fixed submission:
i=1
while 1:
 j=int(input())
 if j==0:
  break
 print("Case",str(i)+":",j)
 i+=1

Buggy python submission (verdict: Runtime Error):
import sys
while 1:
 j=int(input)
 if j==0:
  sys.exit()
 print("Case",str(i)+":",j)

Fixed submission:
i=1
while 1:
 j=int(input())
 if j==0:
  break
 print("Case",str(i)+":",j)
 i+=1

Buggy python submission (verdict: Runtime Error):
while 1:
 i=1
 j=int(input)
 if j==0:
  break
 print("Case",str(i)+":",j)
 i+=1

Fixed submission:
i=1
while 1:
 j=int(input())
 if j==0:
  break
 print("Case",str(i)+":",j)
 i+=1
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
d=0
for i in range(a,b+1)
 if c%i==0:
  d+=1
print(d)

Fixed submission:
a,b,c=map(int,input().split())
d=0
for i in range(a,b+1):
 if c%i==0:
  d+=1
print(d)
Buggy python submission (verdict: Runtime Error):
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])


Fixed submission:
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])

Buggy python submission (verdict: Runtime Error):
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))
 

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


Fixed submission:
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])