#include <bits/stdc++.h>
int main() {
  int n, arr[101], i, c1 = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  if (n == 1) {
    if (arr[0] == 0) {
      printf("0");
    } else {
      printf("1");
    }
  } else if (n == 2) {
    if (arr[0] == 1 && arr[1] == 1) {
      printf("2");
    } else if (arr[0] == 0 && arr[1] == 0) {
      printf("0");
    } else {
      printf("1");
    }
  } else {
    for (i = 0; i < n; i++) {
      if (arr[i] == 1 && arr[i + 1] == 0 && arr[i + 2] == 0) {
        arr[i] = 12;
        arr[i + 1] = 11;
        arr[i + 2] = 20;
        c1++;
      } else if (arr[i] == 1 && arr[i + 1] == 0 && arr[i + 2] == 1) {
        arr[i] = 12;
        arr[i + 1] = 11;
        c1 += 2;
      } else if (arr[i] == 0) {
        arr[i] = 12;
      } else if (arr[i] == 1) {
        arr[i] = 12;
        c1++;
      }
    }
    printf("%d", c1);
  }
}
