#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, t, last, A[10010], next[10010], sum = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);
  A[n] = 0;
  for (i = 0; i < n; i++) {
    if (A[i] == 1) {
      if (sum == 0 || A[i - 1] == 1)
        sum++;
      else
        sum += 2;
    }
  }
  printf("%d\n", sum);
  return 0;
}
