#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v;
  int n, i, t;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> t;
    v.push_back(t);
  }
  while (!v.empty() && *(v.end() - 1) == 0) v.erase(v.end() - 1);
  while (!v.empty() && *v.begin() == 0) v.erase(v.begin());
  for (i = 1; i + 1 < v.size(); i++) {
    if (v[i - 1] == 1 && v[i + 1] == 1) v[i] = 1;
  }
  t = 0;
  for (i = 0; i < v.size(); i++) {
    if (v[i] == 1) t++;
  }
  cout << t << endl;
}
