import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static Map dp = new HashMap<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong(); int m = sc.nextInt(); dp.put(1L, 1L); long prev = sc.nextLong(); long ans = 0; for (int i = 1; i < m; i++) { long x = sc.nextLong(); ans += dfw(x - prev - 1); prev = x; } System.out.println(ans); } static long dfw(long x) { if (x == 1) { return 1; } else if (x % 2 == 0) { return x; } else { return dfw(x / 2) * 2; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }