#include <bits/stdc++.h>
using namespace std;
int bits[1000];
int main() {
  int n, sum = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> bits[i];
  }
  bool flag = false;
  for (int i = 0; i < n; ++i) {
    if (!bits[i] && flag) {
      sum += 1;
      flag = false;
    }
    if (bits[i]) {
      flag = true;
      sum++;
    }
  }
  sum += flag;
  cout << max(sum - 1, 0) << "\n";
  return 0;
}
