import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int[] b = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            b[i] = scanner.nextInt();
        }

        int[][] dp = new int[n + 1][5];
        // rech first pos forwaard only
        dp[1][1] = b[1];
        // cant rech first index with back jump from 2nd
        // its alr visited
        dp[1][2] = Integer.MAX_VALUE;
        // CANT REACH 2ND POS WITH forward jumps
        dp[2][1] = Integer.MAX_VALUE;
        // take cost to reach dp[i-1][1] that is the forward jumps to reach i-1
        // b[3] taken coz we alr need to be at 3 if we can get to 2, IMP :: and the cost at b[3] is dp[1][1]
        // that is forward jumps from dp[i-1][1] since that forward jump from i-1 to i+1 is what lets us be at i + 1 
        // finally take the back jump from i+1.. this is the cost of being at i coming from back jump
        dp[2][2] = b[3] + b[2] + dp[1][1];

        int i = 3;
        while (i <= n-1) {
            dp[i][1] = b[i] + Math.min(dp[i - 2][1], dp[i - 2][2]);
            dp[i][2] = b[i] + b[i + 1] + dp[i - 1][1];
            i++;
        }
        //At n-1 point, the loop has calculated: dp[n-1][1], dp[n-1][2]
        // now for n, we cant come back to n .. either we reach n or we can skip n  
        // if we reached n-1 thru back and took n value then we jump straight out
        //take min of 
        dp[i][2] = b[n] + Math.min(dp[i-2][2],dp[i-2][1]);
        dp[i][1] = 100000000 ; 
        int ans = Math.min(
                dp[n][2],
                Math.min(dp[n - 1][1], dp[n - 1][2])
        );    
        System.out.print(ans);
    }
}
