#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[1005], b[1000], i, c = 0, d, f = 0, n, j = 0, p, r, q = 0, k = 0;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    if (a[i] == 1) {
      d = i;
      break;
    }
  }
  for (i = d; i < n; i++) {
    if (a[i] == 1) f = i;
  }
  for (i = d; i <= f; i++) {
    if (a[i] == 1) q++;
  }
  if (q == 0) {
    cout << q;
    return 0;
  }
  for (i = d; i <= f; i++) {
    if (a[i] == 1)
      continue;
    else {
      r = 0;
      while (a[i] == 0) {
        r++;
        b[j] = r;
        i++;
      }
      j++;
      p = j;
    }
  }
  if (j > 0) {
    for (j = 0; j < p; j++) {
      q = q + 1;
    }
  }
  cout << q;
}
