'''
贪心策略
按照si + wi 和升序排序为最佳序列
'''
n = int(input())
arr = []
for i in range(n):
w, s = map(int, input().split())
arr.append((w+s, w, s))
arr.sort()
S = 0
max_val = -0x7fffffff
for _, w, s in arr:
max_val = max(max_val, S-s)
S += w
print(max_val)