#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<bool> a;
  int n, i, k, x, b, e, ans = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  i = 0;
  while (!a[i]) {
    i++;
    if (i >= n) break;
  }
  b = i;
  i = n - 1;
  while (!a[i]) {
    i--;
    if (i < 0) break;
  }
  e = i;
  i = b;
  while (i <= e) {
    if (a[i] == 1) {
      i++;
      ans++;
    } else {
      k = 0;
      while (a[i + 1] == 0) {
        k++;
        i++;
      }
      if (k == 0) {
        i++;
        ans++;
      } else
        i++;
    }
  }
  cout << ans << endl;
  return 0;
}
