#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[110];
  for (int i = 0; i < n; i++) cin >> a[i];
  int fst = 0, end = 0;
  for (int i = 0; i < n; i++)
    if (a[i] == 1) {
      fst = i;
      break;
    }
  for (int i = n - 1; i >= 0; i--)
    if (a[i] == 1) {
      end = i;
      break;
    }
  int ans = end - fst + 1;
  if (ans == 1) {
    if (a[fst])
      ans = 1;
    else
      ans = 0;
  } else {
    int flag = 0, num = 0;
    for (int i = fst; i < n; i++) {
      if (a[i] == 0) num++;
      if (a[i] == 1) {
        if (num >= 2) ans -= num;
        num = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
