#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, i = 0, count = 0;
  cin >> n;
  if (n == 1) {
    cin >> i;
    if (i) {
      cout << 1;
    } else {
      cout << 0;
    }
    return 0;
  }
  int c[n];
  for (i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (i = 1; i < n - 1; i++) {
    if (c[i]) {
      count++;
    } else if (c[i - 1] * c[i + 1]) {
      count++;
    }
  }
  if (c[0]) {
    count++;
  }
  if (c[n - 1]) {
    count++;
  }
  cout << count;
  return 0;
}
