#include <bits/stdc++.h>
using namespace std;
const int MAXn = 100;
bool p[MAXn + 5];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    while (i < n && p[i] == 1) {
      cnt++;
      i++;
    }
    if (i - 1 >= 0 && i + 1 < n)
      if (p[i] == 0 && p[i - 1] == 1 && p[i + 1] == 1) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
