#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, res = 0, pre = -1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      if (pre == i - 2 && pre != -1) res++;
      res++;
      pre = i;
    }
  }
  cout << res;
  return 0;
}
