from collections import defaultdict, deque, Counter import copy from itertools import combinations, permutations, product, accumulate, groupby, chain from heapq import heapify, heappop, heappush import math import bisect from pprint import pprint from random import randint import sys # sys.setrecursionlimit(700000) input = lambda: sys.stdin.readline().rstrip('\n') inf = float('inf') mod1 = 10**9+7 mod2 = 998244353 def ceil_div(x, y): return -(-x//y) ################################################# def f(n): if n <= 1: return n if n%2 == 0: return n if n%4 == 1: return n-1 return ceil_div(n, 2) N, M = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(M-1): ans += f(A[i+1]-A[i]-1) print(ans)