#include <bits/stdc++.h>
using namespace std;
long a[10001];
int main() {
  long n, i, res = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = 0;
  a[n + 1] = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == 1 && a[i + 2] == 1) {
      a[i + 1] = 1;
    }
  }
  for (i = 0; i < n; i++)
    if (a[i] == 1) res++;
  cout << res << endl;
  return 0;
}
