import java.util.Scanner; class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] data = new int [sc.nextInt()]; int[] vect = new int [data.length]; for(int i = 0 ; i < data.length ; i++)data[i] = sc.nextInt(); if(data.length == 1) { System.out.println(data[0]); return; } if(data.length == 2) { if(data[0] < data[1])System.out.println(data[1]); else System.out.println(data[0]); return; } vect[0] = data[0]; vect[1] = data[1]; for(int i = 2 ; i < data.length ; i++) { int max = 0; for(int j = 0 ; j < i - 1 ; j++) { if(data[i] + vect[j] > max)max = data[i] + vect[j]; } vect[i] = max; } int max = 0; for(int i = 0 ; i < vect.length ; i++) if(max < vect[i])max = vect[i]; System.out.println(max); } }