#include <bits/stdc++.h>
using namespace std;
int main() {
  int T = 1;
  while (T--) {
    int n;
    std::cin >> n;
    ;
    std::vector<int> v(n);
    for (size_t iai = 0; iai < v.size(); iai++) {
      std::cin >> v[iai];
    };
    while (v[0] == 0 && !v.empty()) {
      v.erase(v.begin());
    }
    if (v.size() == 0) {
      std::cout << 0 << std::endl;
      ;
      continue;
    }
    int ans = 0;
    int temp = 0;
    std::reverse(v.begin(), v.end());
    ;
    while (v[0] == 0 && !v.empty()) {
      v.erase(v.begin());
    }
    std::reverse(v.begin(), v.end());
    ;
    if (v.empty()) {
      continue;
    }
    for (int i = 0; i < (int)v.size(); ++i) {
      if (v[i] == 1) {
        ans++;
        temp = 0;
      } else {
        if (temp == 0) {
          ans++;
        }
        temp++;
      }
    }
    std::cout << ans << std::endl;
    ;
  }
  return 0;
}
