#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int arr[n + 10];
  int ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  int i = 1;
  while (arr[i] != 1 && i <= n) {
    i++;
  }
  for (int j = i; j <= n;) {
    if (arr[j] == 0) {
      if (j != n) {
        if (arr[j + 1] == 0) {
          while (arr[j] == 0) {
            j++;
          }
        } else {
          ans++;
          j++;
        }
      } else
        j++;
    } else {
      ans++;
      j++;
    }
  }
  cout << ans << endl;
  return 0;
}
