#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int n, counts = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (a[i] == 1 && a[i + 1] == 0 && i <= n - 2) {
      counts = counts + 2;
    } else if (a[i] == 1)
      counts++;
  }
  if (a[n - 1] == 0) counts--;
  if (counts < 0) counts = 0;
  cout << counts;
}
