#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x0, x1, c = 0, first = 1, seq = 0;
  cin >> n;
  cin >> x0;
  if (x0 == 1) ++c;
  for (int i = 1; i < n; ++i) {
    cin >> x1;
    if (x1 == 1 || x0 == 1) {
      ++c;
    }
    x0 = x1;
  }
  if (x1 == 0 && c > 0) --c;
  cout << c;
  return 0;
}
