#include <bits/stdc++.h>
int main() {
  int n, i, j, count = 0, m = 0;
  scanf("%d", &n);
  int ara[n];
  for (i = 0; i < n; i++) scanf("%d", &ara[i]);
  for (i = 0; i < n; i++) {
    if (ara[i] == 1) {
      for (j = i; j < n; j++) {
        if (ara[j] == 1) {
          count++;
          m = 0;
        } else {
          m++;
          if (j == n - 1) {
            count = count;
            break;
          } else if (ara[j + 1] == 0) {
            count = count;
            j++;
          } else {
            if (m > 1) {
              count++;
              j++;
              m = 0;
            } else
              count++;
          }
        }
      }
      break;
    }
  }
  printf("%d", count);
  return 0;
}
