#include <bits/stdc++.h>
using namespace std;
const int N6 = 1e6 + 6, N3 = 1e3 + 6, oo = 1e9 + 9;
int n, a[N6], ans;
bool ok;
int main() {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (!a[i]) {
      int cnt = 0;
      while (!a[i] && i <= n) {
        ++i;
        ++cnt;
      }
      if ((cnt == 1 && !ok) || (cnt > 1) || (i > n && cnt == 1)) ans += cnt;
    }
    if (a[i]) ok = 1;
  }
  cout << abs(n - ans);
  return 0;
}
