#include <bits/stdc++.h>
using namespace std;
int n, l, r, k;
bool a[100];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(11);
  cout.setf(ios::fixed);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  l = n;
  r = 0;
  k = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i]) {
      l = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (a[i]) {
      r = i;
      break;
    }
  }
  for (int i = l; i <= r; ++i) {
    if (a[i])
      k++;
    else if (a[i - 1] && a[i + 1]) {
      k++;
    }
  }
  cout << 0 + k << endl;
  return 0;
}
