#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  vector<int> vec;
  int cnt = 0, k = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) k++;
    if (a[i] == 1) {
      if (i > 1 && a[i - 1] == 1)
        cnt++;
      else if (k == 1)
        cnt++;
      else
        cnt += 2;
    }
  }
  cout << cnt << endl;
}
