n = raw_input() v = raw_input() r = [] split_v = v.split() for i in range(1, n): if i == 1: r.append (v[0]) if i == 2: r.append (max([v[0], v[1]])) else: r.append(max([v[i-1], v[i-2] + v[i]])) print r[n-1]