N=int(input()) ans=0 p=[0]*(N+1) a=[0]*(N+1) dp1=[0]*(N+1) dp2=[0]*(N+1) for i in range(N): p[i],a[i]=map(int,input().split()) for i in range(N-1,-1,-1): dp1[i]=p[i]+max(dp1[i+1],dp2[i+1]) dp2[i]=a[i]+max(dp1[i+1]+p[i+1],dp2[i+1]+a[i+1]) print(max(dp1[0],dp2[0]))