import strutils, sequtils, algorithm let N, a = stdin.readLine.split.map parseInt var cnt = 0 cnt_L = a.len for i, r in a.reversed: if r < cnt_L: cnt = max(cnt, r) if r == cnt_L: cnt_L -= 1 echo cnt