#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x;
  vector<int> v;
  vector<int> s;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    v.push_back(x);
  }
  if (n == 1 && v[0] == 1) {
    cout << 1;
    return 0;
  }
  if (n == 1 && v[0] == 0) {
    cout << 0;
    return 0;
  }
  int first1, last1;
  int status = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) {
      status = 1;
      first1 = i;
      break;
    }
  }
  if (status == 0) {
    cout << 0;
    return 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (v[i] == 1) {
      last1 = i;
      break;
    }
  }
  for (int i = first1; i < last1 + 1; i++) {
    s.push_back(v[i]);
  }
  int count_ = 0;
  for (int i = 0; i < s.size() - 1;) {
    if (s[i] == 0 && s[i + 1] == 0) {
      while (s[i] == 0) {
        i++;
      }
    } else {
      i++;
      count_++;
    }
  }
  cout << count_ + 1;
  return 0;
}
