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