#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, num;
  cin >> n;
  int ones = 0, sum = 0;
  for (int i = 0; i <= n; i++) {
    if (i == n)
      num = 0;
    else
      cin >> num;
    if (num)
      ones++;
    else if (ones > 0) {
      sum += ((ones - 1) + 2);
      ones = 0;
    }
  }
  cout << ((sum > 0) ? --sum : sum) << endl;
  return 0;
}
