#CCC24J2. Dusa and the Yobis

Dusa and the Yobis

Dusa loves to eat creatures called Yobis — but she only eats Yobis that are smaller than her.

  • If Dusa meets a Yobi that is smaller than her, she eats it and increases her size by the Yobi’s size.
  • If she meets a Yobi that is the same size or larger, she runs away and stops eating.

You are given Dusa’s starting size and a list of Yobis she meets in order. It is guaranteed that she will eventually meet a Yobi that causes her to run away. Determine her size when she runs away.

Input Format

  • The first line contains a positive integer D, Dusa’s initial size.
  • The following lines each contain a positive integer — the size of a Yobi she meets, in order.

Output Format Output a single integer — Dusa’s size when she runs away.

Sample Input

5
3
2
9
20
22
14

Sample Output

19

Explanation: Dusa eats 3, 2, and 9, then runs from 20.