import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import static java.lang.System.in; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String[] inputs = reader.readLine().split(" "); int N = Integer.parseInt(inputs[0]); int M = Integer.parseInt(inputs[1]); inputs = reader.readLine().split(" "); int top = 1; for (int i = M - 1; i > -1; i--) { int a = Integer.parseInt(inputs[i]); if (top == 1) { top = a; } else if (top <= a) { top -= 1; } } System.out.println(top); } }