N = int(input()) M = [int(input()) for _ in range(N)] dp = [float('inf')]*(1<