#include <bits/stdc++.h>
int n;
int a[1000];
void docfile() {
  int i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
}
int vitridau() {
  int i;
  for (i = 0; i < n; i++)
    if (a[i] == 1) return i;
  return -1;
}
int soluong(int k) {
  int t, i;
  t = 1;
  for (i = k + 1; i < n; i++)
    if (a[i] == 1) {
      if (a[i - 1] == 1)
        t = t + 1;
      else
        t = t + 2;
    }
  return t;
}
int main() {
  int vtdau;
  docfile();
  vtdau = vitridau();
  if (vtdau == -1)
    printf("0");
  else
    printf("%d", soluong(vtdau));
  return 0;
}
