#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }
  return a;
}
int main() {
  int n;
  cin >> n;
  int a[200];
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n == 1) {
    cout << a[0];
    return 0;
  }
  int ans = n;
  int i = 0;
  while (i < n && !a[i]) {
    ans--;
    i++;
  }
  int j = n - 1;
  while (j >= i && !a[j]) {
    ans--;
    j--;
  }
  int k = i;
  for (; k < j + 1;) {
    if (!a[k]) {
      int x = k;
      while (k < j + 1 && !a[k]) k++;
      if (k - x >= 2) {
        ans -= k - x;
      }
    } else {
      k++;
    }
  }
  cout << ans;
}
