#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 10000010;
int a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      ans++;
    }
  }
  for (int i = 2; i < n; i++) {
    if (a[i] == 0 and a[i + 1] == 1 and a[i - 1] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
