#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  int i = 0;
  while (a[i] == 0 && i < n) {
    i++;
  }
  int j = n - 1;
  while (a[j] == 0 && j > 0) {
    j--;
  }
  for (; i < j;) {
    if (a[i] == 0 && a[i + 1] == 0) {
      while (i < j && a[i] == 0) {
        i++;
      }
    } else {
      a[i] = 1;
      i++;
    }
  }
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}
