import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for(int i = 0; i < n; i++){
nums[i] = sc.nextInt();
}
int res = nums[0];
for(int i = 1; i < nums.length; i++){
nums[i] += nums[i - 1] > 0 ? nums[i - 1] : 0;
res = Math.max(res, nums[i]);
}
System.out.println(res);
}
}