import sys input = sys.stdin.readline N, M = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(M-1): gap = A[i+1]-A[i] cnt = 1 while True: if gap==2: ans += cnt break elif gap%2!=0: ans += (gap-1)*cnt break else: gap//=2 cnt*=2 print(ans)