//LemonC316 #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> const int maxn = (int)1e5 + 7; const int mod = (int)1e9 + 7; namespace tools { #define ll long long #define mem(x,y) memset(x,y,sizeof(x)) #define pai 3.141592653589793 #define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) using namespace std; template<typename T> inline T max(T x, T y, T z) { return max(x, max(y, z)); } template<typename T> inline T min(T x, T y, T z) { return min(x, min(y, z)); } template<typename T> inline void debug(T x, T y){cout << x << " " << y << endl;} template<typename T> inline void debug(T x){cout << x << endl;} template<typename T> inline void read(T& ans){T x = 0, f = 1; char c = getchar(); while (c < '0' || c>'9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar();ans = f * x;} inline ll read(){ll s = 0, bj = 0;char ch = getchar(); while (ch < '0' || ch>'9')bj |= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9')s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();return bj ? -s : s;} template<typename T> inline void write(T x){if (x < 0) x = ~x + 1, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0');} }using namespace tools; int dp[2], n; int main() { read(n); for (int i = 0; i < n; ++i) { if (read()) dp[0] = min(dp[0] + 1, dp[1] + 1), dp[1] = min(dp[0] + 1, dp[1]); else dp[0] = min(dp[0], dp[1] + 1), dp[1] = min(dp[0] + 1, dp[1] + 1); } write(dp[0]); return 0; }