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