#include <bits/stdc++.h>
using namespace std;
long long int facs[1000001];
long long int inv_modulo(long long int a, long long int b) {
  long long int b0 = b, t, q;
  long long int x0 = 0, x1 = 1;
  if (b == 1) return 1;
  while (a > 1) {
    q = a / b;
    t = b, b = a % b, a = t;
    t = x0, x0 = x1 - q * x0, x1 = t;
  }
  if (x1 < 0) x1 += b0;
  return x1;
}
void factorial() {
  long long int n = 1000000;
  facs[1] = 1;
  facs[0] = 0;
  long long int fac = 1;
  for (long long int i = 2; i <= n; i++) {
    fac = (fac * i) % 1000003;
    facs[i] = fac;
  }
}
string preProcess(string s) {
  int n = s.length();
  if (n == 0) return "^$";
  string ret = "^";
  for (int i = 0; i < n; i++) ret += "#" + s.substr(i, 1);
  ret += "#$";
  return ret;
}
string longestPalindrome(string s) {
  string T = preProcess(s);
  int n = T.length();
  int *P = new int[n];
  int C = 0, R = 0;
  for (int i = 1; i < n - 1; i++) {
    int i_mirror = 2 * C - i;
    if (R > i) {
      P[i] = min(R - i, P[i_mirror]);
    } else {
      P[i] = 0;
    }
    while (T[i + 1 + P[i]] == T[i - (1 + P[i])]) {
      P[i]++;
    }
    if (i + P[i] > R) {
      C = i;
      R = i + P[i];
    }
  }
  int maxLen = 0;
  int centerIndex = 0;
  for (int i = 1; i < n - 1; i++) {
    if (P[i] > maxLen) {
      maxLen = P[i];
      centerIndex = i;
    }
  }
  int start = (int)(centerIndex - 1 - maxLen) / 2.00;
  int fin = maxLen;
  return s.substr(start, fin);
}
long long int bigmod(long long int a, long long int b, long long int M) {
  if (b == 0) return 1;
  long long int x = bigmod(a, b / 2, M);
  x = (x * x) % M;
  if ((b & 1) == 1) x = (x * a) % M;
  return x;
}
template <typename t1>
t1 gcd(t1 a, t1 b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename t1>
t1 lcm(t1 a, t1 b) {
  return a * (b / gcd(a, b));
}
bool check(int i, int k) { return i & (1 << k); }
int On(int i, int k) { return i | (1 << k); }
int Off(int i, int k) { return (i - ((check(i, k)) << k)); }
int gray_to_int(int n) {
  int lm = -1;
  int binary = 0;
  for (int i = 31; i >= 0; i--) {
    if (check(n, i) == 1) {
      lm = i;
      break;
    }
  }
  if (lm == -1) return 0;
  binary = On(binary, lm);
  for (int i = lm - 1; i >= 0; i--) {
    bool ck = check(n, i);
    bool prev = check(binary, i + 1);
    if (ck == 0 && prev == 0) {
      binary = Off(binary, i);
    } else if (ck == 1 && prev == 1) {
      binary = Off(binary, i);
    } else if (ck == 0 && prev == 1) {
      binary = On(binary, i);
    } else if (ck == 1 && prev == 0) {
      binary = On(binary, i);
    }
  }
  return binary;
}
int main() {
  int n;
  scanf("%d", &n);
  int arr[n + 1];
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  int counter = 0;
  for (int i = 1; i < n - 1; i++) {
    if ((arr[i] == 0 && arr[i + 1] == 0) || (arr[i] == 0 && arr[i - 1] == 0)) {
      continue;
    } else {
      arr[i] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    counter += arr[i];
  }
  cout << counter << endl;
  return 0;
}
