#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int count = 0, count2 = 0;
  int i, j, k = -1;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    if (a[i] == 1) {
      k = i;
      break;
    }
  }
  if (k == -1) {
    cout << "0";
    return 0;
  }
  for (i = k; i < n;) {
    if (a[i] == 1) {
      count++;
      i++;
    } else {
      for (j = i;; j++) {
        if (a[j] == 1)
          break;
        else
          count2++;
      }
      if (count2 == 1) {
        i++;
        count++;
        count2 = 0;
      } else {
        i += count2;
        count2 = 0;
      }
    }
  }
  cout << count;
  return 0;
}
