#include <bits/stdc++.h>
using namespace std;
template <class T, class T1>
int chkmax(T &x, const T1 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T1>
int chkmin(T &x, const T1 &y) {
  return x > y ? x = y, 1 : 0;
}
const int MAXN = (int)5e3 + 42;
const int inf = (int)1e9;
int n;
int a[MAXN];
void read() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
}
int dp[MAXN][5];
int rec(int i, int last) {
  if (i == n) return 0;
  int &memo = dp[i][last];
  if (memo != -1) return memo;
  memo = inf;
  if (last == 4) {
    chkmin(memo, rec(i + 1, a[0]));
    if (a[0]) chkmin(memo, 1 + rec(i + 1, 0));
  } else {
    if (a[i] && last == 2)
      chkmin(memo, 1 + rec(i + 1, 0));
    else {
      chkmin(memo, rec(i + 1, ((last << 1) | a[i]) & 3));
      if (a[i]) chkmin(memo, 1 + rec(i + 1, (last << 1) & 3));
    }
  }
  return memo;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  cout << rec(0, 4) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
