#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int num[maxn];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) scanf("%d", &num[i]);
    int st = -1, ans = 0;
    for (int i = 0; i < n; i++) {
      if (num[i]) {
        st = i;
        break;
      }
    }
    if (st == -1) {
      printf("0\n");
      continue;
    }
    num[n] = 0;
    for (int i = st; i < n; i++) {
      if (num[i] == 1) {
        ans++;
        continue;
      }
      if (num[i - 1] == 1 && num[i + 1] == 1) ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
