#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, total, t;
  cin >> n;
  vector<int> letters;
  int fone = -1;
  int lone = -1;
  for (int i = 0; i < n; i++) {
    cin >> t;
    if (fone < 0 && t == 1) fone = i;
    if (t == 1) lone = i;
    letters.push_back(t);
  }
  total = 1;
  if (fone < 0) {
    cout << "0";
    return 0;
  }
  int open = 0;
  total = 0;
  for (int i = fone; i < n; i++) {
    if (!open && letters[i]) {
      total++;
      open = 1;
    } else if (open && letters[i]) {
      total++;
    } else if (open && !letters[i]) {
      if (i + 1 < n && letters[i + 1]) {
        total += 1;
      } else if (i + 1 < n && !letters[i + 1]) {
        open = 0;
        total += 1;
      }
    }
    if (lone == i) break;
  }
  cout << total;
  return 0;
}
