#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, temp = 0, p = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) temp++;
  }
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == 1 && a[i + 1] == 1) {
      p++;
    }
  }
  if (temp == 0) {
    cout << 0;
    return 0;
  }
  cout << 2 * temp - p - 1;
}
