#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0, f = 1, k = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      k = i;
    }
  }
  for (int i = 0; i <= k; i++) {
    if (a[i] == 1) {
      f = 0;
      ans++;
    } else if (a[i] == 0 && !f) {
      if (a[i + 1] == 0) {
        continue;
      } else {
        ans++;
      }
    }
  }
  cout << ans;
}
