a,b=[],[] for i in range(int(input())-1): c,d=map(int,input().split()) a.append(c) b.append(d) i = max(b) - sum(a) + a[b.index(max(b))] d = sum(b)+1 if i < 0: i=0 print(d-i)