#include <bits/stdc++.h>
using namespace std;
int n, a[1000];
int main() {
  int res = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  a[++n] = 0;
  a[++n] = 0;
  int start = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) {
      if (start == 0) start = i;
    } else {
      if (a[i - 1] == 0)
        if (start != 0) {
          res += (i - start - 1);
          start = 0;
        }
    }
  cout << res;
}
