#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n + 1];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long t = 0;
  bool f;
  for (long long i = 0; i < n; i++) {
    if (a[i] == 1) {
      while (a[i] == 1) t++, i++;
      i--;
      t++;
    }
  }
  if (t) t--;
  cout << t << "\n";
}
