#include <bits/stdc++.h>
int main() {
  int n, cnt = 0, home = 0;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0 && home % 2 == 0)
      continue;
    else if (a[i] == 0 && home % 2 == 1) {
      if (a[i + 1] == 1)
        cnt++;
      else
        home++;
    } else if (a[i] == 1 && home % 2 == 0) {
      cnt++;
      home++;
    } else
      cnt++;
  }
  printf("%d", cnt);
  return 0;
}
