#include <iostream>
using namespace std;
int main() {
int n = 0;
int cost[100010] = {0};
int min1 = 0;
int min2 = 0;
int min3 = 0;
cin >> n;
for (int i = 0; i < n && (cin >> cost[i]); i++);
if (n <= 2)
{
cout << ((cost[0] < cost[1]) ? cost[0] : cost[1]);
}
else
{
min1 = cost[0];
min2 = cost[1];
min3 = 0;
for (int i = 3; i <= n; i++)
{
min3 = (cost[i - 3] > cost[i - 2]) ? cost[i - 2] : cost[i - 3];
cost[i - 1] += min3;
}
cout << ((cost[n - 1] < cost[n - 2]) ? cost[n - 1] : cost[n - 2]);
}
return 0;
}
// 64 位输出请用 printf("%lld")