#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int i = 0, num = 0;
  while (i < n) {
    if (arr[i] == 1) {
      num += 1;
      i++;
    } else if (arr[i] == 0 && i == 0) {
      while (arr[i] == 0) {
        i++;
      }
    } else if (arr[i] == 0) {
      while (arr[i] == 0) {
        i++;
      }
      if (i < n) num += 1;
    }
  }
  cout << num << endl;
}
