import strutils, sequtils, algorithm let N, a = stdin.readLine.split.map(parseInt).reversed proc jenga(a: seq[int]): int = if a[0] == a.max: result = jenga a[1 .. ^1] else: for a_i in a: if a_i == a.max: return result result = max(result, a_i) if a == a.sorted(cmp, Descending): echo 0 else: echo a.jenga