#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = map(int, read().split()) A, B = zip(*zip(m, m)) A = (0,) + A B = (0,) + B + (0,) INF = 10 ** 18 dp = [-INF] * (N + 1) # その商品を最後に手数料対象とするときの、最適な節約額 dp1 = [-INF] * (N + 1) dp1[0] = B[1] for i in range(1, N + 1): dp[i] = dp1[i - 1] - A[i] if dp[i - 1] > dp[i]: dp[i] = dp[i - 1] dp1[i] = max(dp1[i - 1], dp[i] + B[i + 1]) save = max(dp[1:]) answer = sum(A) + sum(B) - save print(answer)