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