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