#include <bits/stdc++.h>
int n;
int a[110];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int state = 0;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    if (a[i])
      state = 1;
    else {
      if (i != n - 1) {
        if (state) {
          if (a[i + 1])
            sum++;
          else
            state = 0;
        }
      }
    }
  }
  printf("%d\n", sum);
  return 0;
}
