#include <bits/stdc++.h>
using namespace std;
template <class X>
void input(vector<X>& a, int N) {
  X temp;
  for (long long int i = 0; i < N; i++) {
    cin >> temp;
    a.push_back(temp);
  }
}
void solve() {
  int N;
  cin >> N;
  bool found = false;
  int counter = 0;
  bool last = 0;
  int nums1 = 0;
  for (long long int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    if (temp == 1) {
      found = true;
      nums1++;
    }
    if (last == 0 && temp == 1) {
      counter++;
    }
    last = temp;
  }
  if (found)
    cout << nums1 + counter - 1;
  else
    cout << 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
