#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 1) count++;
  }
  int i;
  for (i = 0; i < n; i++)
    if (arr[i] == 1) break;
  int list1 = 0, list2 = 0;
  for (; i < n; i++) {
    if (arr[i + 1] == 0 && arr[i + 2] == 0) {
      if (i + 2 < n - 1) i++;
      while (arr[i] != 1 && i < n) {
        i++;
        if (arr[i] == 1) list1++;
      }
    }
    if (arr[i + 1] == 0 && arr[i + 2] != 0) {
      if (i + 1 < n - 1) list2++;
    }
  }
  cout << count + list1 + list2;
  return 0;
}
