#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt = 0;
  int uni = 0;
  int no;
  cin >> no;
  int arr[no + 10];
  for (int i = 0; i < no; i++) cin >> arr[i];
  int i = 0;
  while (i < no && arr[i] == 0) i++;
  if (i >= no) {
    cout << "0\n";
    return 0;
  }
  int l = no - 1;
  while (l >= 0 && arr[l] == 0) l--;
  for (int j = i; j <= l; j++) {
    if (arr[j] == 1) uni++;
    if (arr[j] == 0) {
      if (j + 1 <= l && j - 1 >= 0 && arr[j + 1] == 0 || arr[j - 1] == 0) {
      } else
        uni++;
    }
  }
  cout << uni << "\n";
  return 0;
}
