#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, tmp = 0;
  scanf("%d", &n);
  int arr[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  i = 0;
  while (i <= n - 1) {
    if (arr[i] == 1) {
      tmp += 2;
      i++;
      while (arr[i] == 1 && i <= n - 1) {
        i++;
        tmp++;
      }
    } else
      i++;
  }
  if (tmp != 0)
    printf("%d\n", tmp - 1);
  else
    printf("0\n");
}
