N,M = map(int,input().split()) C = 10 ** 6 dp = [0] * C dp[1] = 1 dp[2] = 2 for i in range(3,C): if i % 2 == 1: dp[i] = dp[i//2] * 2 else: dp[i] = dp[i // 2] * 2 + dp[i // 2 - 1] * 2 def calc(n): if n < C: return dp[n] else: if n % 2 == 1: return 2 * calc(n // 2) else: return (calc(n // 2) + calc(n // 2 - 1)) * 2 ans = 0 for i in range(M - 1): ans += calc(A[i + 1] - A[i]) print(ans)