#include <bits/stdc++.h>
using namespace std;
int a[111];
int main() {
  int n;
  scanf("%d", &n);
  a[0] = -1;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  a[n + 1] = -1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i - 1] == 1 && a[i + 1] == 1) a[i] = 1;
    ans += a[i];
  }
  printf("%d\n", ans);
  return 0;
}
