#P10291. Dusa and Yobi
Dusa and Yobi
Dusa and Yobi
Dusa enjoys eating Yobi, but she only eats those that are strictly smaller than her current size. When Dusa encounters a Yobi of size \(y\) and her current size is \(S\), if \(S > y\) then she eats it and her new size becomes \(S + y\) (i.e. \(S' = S + y\)). However, if she encounters a Yobi with size \(y\) such that \(y \ge S\), she escapes immediately without eating it. You are given the initial size of Dusa and a sequence of Yobi encountered in order. It is guaranteed that at some point Dusa will encounter a Yobi that is not smaller than her current size. Determine the size of Dusa at the moment she escapes.
inputFormat
The first line contains two integers: the initial size of Dusa and the number of Yobi \(n\). The second line contains \(n\) integers, which are the sizes of the Yobi in the order they are encountered.
outputFormat
Output a single integer representing Dusa's size at the moment she escapes.
sample
10 3
6 16 2
16