#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0;
  cin >> n;
  bool* V = new bool[n];
  bool Back = false;
  for (int i = 0; i < n; ++i) {
    cin >> V[i];
    if (V[i]) {
      if (Back && c) c++;
      c++;
      Back = false;
    } else {
      Back = true;
    }
  }
  cout << c << endl;
  return 0;
}
