#include <bits/stdc++.h>
using namespace std;
int a[110];
int kq, dem, n;
void solve() {
  int i;
  kq = 0;
  dem = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == 1) {
      if (dem == 1 && kq != 0) {
        kq++;
      }
      kq++;
      dem = 0;
    } else {
      dem++;
    }
  }
  printf("%d\n", kq);
}
int main() {
  int i;
  while (scanf("%d", &n) == 1) {
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    solve();
  }
  return 0;
}
