#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  int c = 0, count;
  for (j = 0; j < n; j++) {
    if (a[j] == 1) break;
  }
  for (k = n - 1; k > -1; k--) {
    if (a[k] == 1) break;
  }
  for (i = j; i <= k; i++) {
    if (a[i] == 1) {
      c++;
      count = 0;
    } else {
      count++;
      if (count == 1) c++;
    }
  }
  cout << c;
  return 0;
}
