n, m = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(m - 1): d = A[i + 1] - A[i] ans += d - 1 minus = 1 while d % 2 == 0 and d > 2: d //= 2 ans -= minus minus *= 2 print(ans)