#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[10001];
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int cnt = 0;
  if (n > 2)
    for (int i = 1; i < n - 1; ++i) {
      cnt += a[i];
      if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1) cnt++;
    }
  if (n == 1)
    cout << a[0];
  else
    cout << cnt + a[0] + a[n - 1];
  return 0;
}
