#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 100 * 1000 + 17;
int n, a[MAXN], t = MAXN, ans;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i]) t = min(t, i);
  }
  for (int i = t; i <= n; i++) {
    if (a[i])
      ans++;
    else if (a[i + 1] and a[i - 1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
