N = int(input()) l = [] for _ in range(N): p,a = map(int,input().split()) l.append((p,a)) dp = [[0] * 2 for _ in range(N)] dp[0][0] = l[-1][0] dp[0][1] = l[-1][1] for i in range(1,N): p,a = l[-1-i] pp,aa = l[-i] dp[i][1] = max(dp[i-1][0] + pp,dp[i-1][1] + aa) + a dp[i][0] = max(dp[i-1][0],dp[i-1][1]) + p print(max(dp[-1]))