object Main {

    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        while(sc.hasNext){
            val n = sc.nextInt
            var list = List.empty[Int]
            for(_ <- 1 to n){
            	val a = sc.nextInt
	            if(list.isEmpty) list = a :: list
	            else list = Math.max(list.take(1)(0) + a, a) :: list
        	}
            println(list.max)
        }
    }
}