#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
  int n;
  int ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int id = 0;
  while ((id < n) && (a[id] == 0)) {
    ++id;
  }
  while (id < n) {
    while ((id < n) && (a[id] == 1)) {
      ++id;
      ++ans;
    }
    while ((id < n) && (a[id] == 0)) {
      ++id;
    }
    if (id < n) {
      ans += 2;
    }
    ++id;
  }
  cout << ans << endl;
  return 0;
}
