#include <bits/stdc++.h>
using namespace std;
long long a[1000000], b[1000000], c[1000000], n, m, t,
    flag = 0, flag2 = 0, cnt = 0, cnt1 = 0, ans = 0;
string s, s1, s2;
int main() {
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> m;
    if (m) v.push_back(i);
  }
  int sz = v.size();
  if (sz) ans = 1;
  for (int i = 0; i < sz - 1; i++) {
    if (v[i + 1] - v[i] == 1)
      ans++;
    else
      ans += 2;
  }
  cout << ans;
  return 0;
}
