#include <bits/stdc++.h>
using namespace std;
int main() {
  int ar[1001];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  vector<int> v;
  v.clear();
  for (int i = 0; i < n; i++) {
    if (ar[i] == 1) {
      v.push_back(i);
    }
  }
  int cou = 0;
  if (!v.empty()) {
    for (int i = 0; i < v.size() - 1; i++) {
      if (v[i] + 1 == v[i + 1]) {
        cou++;
      } else {
        cou += 2;
      }
    }
    if (v.size() == 1) {
      cout << 1 << endl;
      return 0;
    }
  }
  if (cou != 0)
    cout << cou + 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}
