#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int a[maxn], pos[maxn];
int n;
int main() {
  while (scanf("%d", &n) != EOF) {
    memset(a, 0, sizeof a);
    memset(pos, 0, sizeof pos);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int cnt = 0;
    int t = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        pos[t++] = i;
      }
    }
    int k = 0;
    pos[t] = 10000000;
    for (int i = 1; i <= t; i++) {
      if (pos[i] - pos[i - 1] <= 2) {
        cnt += pos[i] - pos[i - 1];
      } else
        cnt++;
    }
    printf("%d\n", cnt);
  }
}
