#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0;
  cin >> n;
  int ans = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  a.emplace_back(0);
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      ans++;
      s = 1;
    } else if (a[i] == 0 && a[i + 1] == 0) {
      s = 0;
    } else if (a[i] == 0 && s == 0) {
      continue;
    } else if (a[i] == 0 && s == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}
