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