import strutils, sequtils, algorithm proc getStr: auto = stdin.readLine proc go(V: seq[int]): int = var i = 0 while i < V.len: if i != V.high: if V[i] < V[i + 1]: inc i continue inc result, V[i] inc i, 2 let N = getStr().parseInt V = getStr().split.map parseInt echo max(V.go, V.reversed.go)