#include <bits/stdc++.h>
using namespace std;
int n, x;
int main() {
  cin >> n;
  bool b = false;
  int cont = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (b) {
      if (x)
        ++cont;
      else
        b = false;
    } else {
      if (x) {
        if (cont) ++cont;
        b = true;
        ++cont;
      }
    }
  }
  cout << cont << endl;
}
