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