#include <bits/stdc++.h>
using namespace std;
int A[112345], B[112345];
int main() {
  int n, l;
  cin >> n;
  if (n == 1) {
    cin >> l;
    if (l) {
      cout << 1 << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  }
  int j = 0, a = 0, f = 1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 0 && f) {
      continue;
    } else {
      f = 0;
      A[j++] = a;
    }
  }
  int s = 1;
  int k = 0;
  for (int i = j - 1; i >= 0; i--) {
    if (A[i] == 0 && s) {
      continue;
    } else {
      B[k++] = A[i];
      s = 0;
    }
  }
  int sum = 0;
  int zero = 0, xc = 0;
  for (int i = 0; i < k; i++) {
    if (B[i] == 1) {
      if (zero >= 2) xc += zero;
      zero = 0;
    } else {
      zero++;
      continue;
    }
  }
  cout << k - xc << endl;
}
