#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  int sum = 0;
  int q = 0;
  cin >> n;
  bool is_begin = false;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    if ((t == 0) && (!is_begin)) {
      continue;
    }
    if ((t == 1) && (!is_begin)) {
      is_begin = true;
    }
    if (t == 1) {
      if (q == 1) {
        sum += 2;
      } else {
        sum++;
      }
      q = 0;
    } else {
      q++;
    }
  }
  cout << sum << endl;
  return 0;
}
