while 1:
    try:
        n = int(input())
        cost = list(map(int, input().split(' ')))
        dp = [0]*(n+1)
        for i in range(2, n+1):
            dp[i] = min(dp[i-1]+cost[i-1], dp[i-2]+cost[i-2])
        print(dp[n])
    except:
        break