package BOJ.DP;
import java.util.Arrays;
import java.util.Scanner;
public class BOJ_11055 {
static int[] number;
static int[] answer;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
number = new int[n + 1];
answer = new int[n + 1];
for (int i = 1; i <= n; i++) {
number[i] = Integer.parseInt(sc.next());
}
solve(n);
System.out.println(Arrays.stream(answer).max().getAsInt());
}
private static void solve(int n) {
for(int i=1; i<=n; i++){
answer[i] = number[i];
for(int j=1; j<i; j++){
if(number[j] < number[i] && answer[i] < answer[j] + number[i])
answer[i] = answer[j] + number[i];
}
}
}
}