n = int(input()) p, a = map(int, input().split()) pp = p aa = a for _ in range(n - 1): p, a = map(int, input().split()) p_tmp = max(pp + p, aa + p * 2) a_tmp = max(pp + a, aa + a * 2) pp = p_tmp aa = a_tmp print(max(pp, aa))