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