#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n], ans = 0, zero = 0, f;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  f = a[0] == 0 ? 1 : 0;
  for (int i = 0; i < n; i++) {
    if (f == 1 && a[i] == 0)
      continue;
    else if (a[i] == 1) {
      f = 0;
      if (zero > 1 && a[i] == 1)
        ans++;
      else if (zero <= 1 && a[i] == 1)
        ans += 1 + zero;
      zero = 0;
    } else
      zero++;
  }
  printf("%d\n", ans);
  return 0;
}
