import math._ object Main { def calc(n: Int, xs: Array[Int]): Int = { var p = 1 for (x <- xs.reverse) { if (p == 1) p = x else if (x >= p) p -= 1 } p } def main(args: Array[String]) { val sc = new java.util.Scanner(System.in) val n, m = sc.nextInt var xs = Array.fill(m)(sc.nextInt) println(calc(n, xs)) } }