#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum;
  int a[100 + 10];
  while (cin >> n) {
    sum = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    a[0] = 0, a[n + 1] = 0;
    for (int i = 0; i <= n; i++) {
      if (a[i] == 1) sum++;
      if (a[i - 1] == 1 && a[i] == 0 && a[i + 1] == 1 && i != 0) sum++;
      if (a[i] == 0 && a[i + 1] == 0) i++;
    }
    cout << sum << endl;
  }
}
