#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  size_t n;
  std::cin >> n;
  std::vector<int32_t> a(n);
  for (size_t i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  size_t result = 0;
  bool in = false;
  bool window = false;
  for (size_t i = 0; i < n; ++i) {
    if (a[i] != 0) {
      in = true;
      result += 1 + window;
      window = false;
    } else {
      if (in && !window) {
        window = true;
      } else {
        in = false;
        window = false;
      }
    }
  }
  std::cout << result << '\n';
}
