#include <bits/stdc++.h>
using namespace std;
int N;
int A[101];
int ans = 0;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  ans = 0;
  int i = 0;
  while (i <= N && A[i] == 0) {
    i++;
  }
  int j = N;
  while (j >= 0 && A[j] == 0) {
    j--;
  }
  ans = j - i + 1;
  int zeros = 0;
  int ones = 0;
  for (int k = i; k <= j; k++) {
    if (A[k] == 1) ones++;
    if (A[k] == 0 && k - 1 >= i && A[k - 1] == 1 && k + 1 <= j &&
        A[k + 1] == 1) {
      zeros++;
    }
  }
  cout << zeros + ones << endl;
}
