#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int i = 0;
  for (i = 0; i < n; i++) cin >> a[i];
  vector<int> v;
  int count = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == 1) {
      count++;
    } else {
      v.push_back(count);
      count = 0;
    }
  }
  v.push_back(count);
  int len = v.size();
  int ans = 0;
  bool flag = false;
  for (i = 0; i < len; i++) {
    if (v[i] == 0) continue;
    flag = true;
    ans += v[i] + 1;
  }
  if (flag) ans--;
  cout << ans << endl;
  return 0;
}
