N=int(input()) P=[0]*(N+1) A=[0]*(N+1) for i in range(1,N+1): p,a=map(int,input().split()) P[i]=p A[i]=a S=[[0,0] for _ in range(N+1)] S[-1][0]=P[-1] S[-1][1]=A[-1] for i in range(N-1,-1,-1): S[i][0]=max(S[i+1][0],S[i+1][1])+P[i] S[i][1]=max(S[i+1][0]+P[i+1],S[i+1][1]+A[i+1])+A[i] print(S[0][0])