#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0, n, f = 1, g = 0, x;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (f == 0 && x == 0) {
      g = 1;
      f = 1;
      ans++;
      continue;
    }
    if (x)
      ans++, f = 0;
    else if (g)
      ans--, f = 1;
    g = 0;
  }
  if (x == 0 && g) ans--;
  printf("%d\n", ans);
}
