import java.io.BufferedInputStream; import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; public class Main { public static final int C = 1000000007; //static boolean MAP[][]; static int N; static int M; static int MAX = -1; //static int tic[][]; static boolean NUM[]; //static int max; static int A[]; static int ST[][]; //static int p[]; //static ArrayList> al; static TreeMap> hm; //static ArrayList al; //static int a[][]; //static char[][] ch; //static ArrayList> al; //static String a[]; //static String str; //static int[] mach = new int[] {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; public static void main(String[] args) { StringBuilder sb = new StringBuilder(); BufferedInputStream bs = new BufferedInputStream(System.in); Scanner sc = new Scanner(bs); N = sc.nextInt(); M = sc.nextInt(); int a[] = new int[M]; for (int i=0; i < M; i++) { a[i] = sc.nextInt(); } int ans = 1; for (int i=M-1; i >= 0; i--) { if (ans == 1) { ans = a[i]; }else if (ans < a[i]) { ans--; }else { } } System.out.println(ans); } }