def soln(L): if L%2 == 0: return L if L == 1: return 1 return 2*soln((L-1)//2) N, M = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(M-1): ans += soln(A[i+1]-A[i]-1) print(ans)