import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] p = br.readLine().split(" ");
        int[] dp = new int[n+1];
        
        for(int i=1; i<n+1; i++) { dp[i] = 10001; }
        
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=i; j++) {
                dp[i] = Math.min(dp[i], dp[i-j]+Integer.parseInt(p[j-1]));
            }
        }
        
        System.out.println(dp[n]);
    }
}