1N = int(input())
2P = list(map(int, input().split()))
3dp = [10000000]*(N)
4
5for i in range(N):
6 for j in range(i):
7 dp[i] = min(dp[i], dp[j]+P[i-j-1])
8 dp[i] = min(dp[i], P[i])
9
10print (dp[N-1])
1N = int(input())
2P = list(map(int, input().split()))
3dp = [10000000]*(N)
4
5for i in range(N):
6 for j in range(i):
7 dp[i] = min(dp[i], dp[j]+P[i-j-1])
8 dp[i] = min(dp[i], P[i])
9
10print (dp[N-1])