local ffi = require 'ffi' local C, ct = ffi.C, ffi.typeof 'int8_t[1]' ffi.cdef 'int scanf(const char *, ...);' print((function (p, n) local a,b={},{} for i=1,n do C.scanf("%d",p) a[i]=p[0] end if n==1 then return a[1] end if n==2 then return a[1]>a[2] and a[1] or a[2] end b[1],b[2] = a[1],a[1]>a[2] and a[1] or a[2] for i=3,n do b[i] = b[i-2]+a[i]>b[i-1] and b[i-2]+a[i] or b[i-1] end return b[n] end)(ct(), io.stdin:read("*n")))