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