x,N = [int(i) for i in input().split()] a = [x**int(i) for i in input().split()] print(sum(a))