Under construction

Still being built. Things may change

Dusa and the Yobis

Time limit1sMemory limit1024 MB

Summary
Dusa starts at size D and eats each Yobi smaller than itself, gaining that Yobi's size. Find Dusa's size when it first meets a Yobi that is not smaller.
Level

Easy2 of 10

Topics
Implementation, Simulation
Solved
No attempts yet

Problem

Dusa eats Yobis, but only Yobis of a certain size.

If Dusa encounters a Yobi that is smaller than itself, it eats the Yobi, and absorbs its size. For example, if Dusa is of size 10 and it encounters a Yobi of size 6, Dusa eats the Yobi and expands to size 10 + 6 = 16.

If Dusa encounters a Yobi that is the same size as itself or larger, Dusa runs away without eating the Yobi.

Dusa is currently facing a line of Yobis and will encounter them in order. Dusa is guaranteed to eventually encounter a Yobi that causes it to run away. Your job is to determine Dusa's size when this happens.

Input

The first line of input contains a positive integer, D, representing Dusa's starting size.

The remaining lines of input contain positive integers representing the sizes of the Yobis in order.

Output

Output the positive integer, R, which is Dusa's size when it eventually runs away.

Examples2

  1. Example 1

    Input
    5
    3
    2
    9
    20
    22
    14
    
    Expected output
    19
    
  2. Example 2

    Input
    10
    10
    3
    5
    13
    
    Expected output
    10