#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  int a[101];
  while (scanf("%d", &n) != EOF) {
    int cnt = 0;
    int x = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
      if (a[i]) {
        if (x > 1) x = 0;
        cnt += x + 1;
        x = 0;
      } else {
        if (cnt) x++;
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
