#include<bits/stdc++.h>
#define ll long long int

#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define print_upto(a,n)        for(int i=0;i<n;i++)    cout<<a[i]<<" "; cout<<endl
#define take(x,n)           for(int i=0;i<n;i++)  cin>>x[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	ll n;
	cin >> n;

	ll a[1000003] = {0};
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}

	ll dp[ 1000009] = {0};
	dp[0] = a[0];
	dp[1] = a[1];
	dp[2] = a[2];

	for (ll i = 3; i < n; i++) {
		dp[i] = a[i] + min(dp[i - 1], min(dp[i - 2], dp[i - 3]));
	}

	if (n == 1)
		cout << dp[0] << "\n";
	else if (n == 2)
		cout << min(dp[0], dp[1]) << "\n";
	else
		cout << min(dp[n - 1], min(dp[n - 2], dp[n - 3])) << "\n";


	return 0;
}