#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  int a[n], ans = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool flag = false;
  int step = 0;
  for (i = 0; i < n;) {
    while (a[i] != 1 && i < n) i++, step++;
    if (i >= n) break;
    if (!flag) {
      ans++;
      flag = true;
    } else
      ans += min(2, step);
    i++;
    step = 1;
  }
  cout << ans;
  return 0;
}
