#include <bits/stdc++.h>
using namespace std;
int main() {
  int T[100];
  bool t(false);
  int n, i, j, s(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> T[i];
  if (T[1] == 0) s++;
  if (n != 1 && T[n] == 0) s++;
  i = 1;
  while (i < n) {
    j = i;
    while ((T[j] == T[j + 1]) && (T[j] == 0) && (j < n)) {
      if (t) s--;
      if (j == 1) s--;
      if (j + 1 == n) s--;
      s = s + 2;
      j++;
      t = true;
    }
    if (j < n)
      i = j + 1;
    else
      break;
    t = false;
  }
  cout << n - s;
  return 0;
}
