import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### def f(x): if x == 0: return 0 if x == 1: return 1 if x % 2 == 0: return x return f((x-1)//2) * 2 n, m = na() a = na() ans = 0 for i in range(m-1): ans += f(a[i+1] - a[i] - 1) print(ans)