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