#include <bits/stdc++.h>
int main() {
  int n, i, a[110], count = 0, s = 4, k = 7;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++)
    if (a[i] == 1) break;
  k = i;
  for (i = n; i > 0; i--)
    if (a[i] == 1) break;
  s = i;
  for (i = k; i <= s; i++)
    if (a[i] == 0 && a[i + 1] == 0)
      i++;
    else if (a[i] == 0 && a[i - 1] == 0)
      ;
    else
      count++;
  printf("%d", count);
  return 0;
}
