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