#include <bits/stdc++.h>
int num[1111];
int main() {
  int n, i;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &num[i]);
  int oper = 0, zero = 0;
  for (i = 0; i < n; i++)
    if (num[i]) break;
  for (; i < n; i++) {
    if (num[i]) {
      oper++;
      if (zero) {
        oper++;
        zero = 0;
      }
    } else
      zero++;
  }
  printf("%d\n", oper);
  return 0;
}
