#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  int a[100];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  a[n] = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == 1) {
      if (a[i + 1] == 0 && a[i + 2] == 1) {
        a[i + 1] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i]) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
