#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, c, s = 0, cnt = 0, j;
  cin >> n;
  bool first = false;
  for (i = 0; i < n; i++) {
    cin >> c;
    if (c == 0) {
      if (first) {
        cnt++;
      }
    }
    if (c == 1) {
      if (first == false) {
        s++;
        first = true;
      } else if (cnt == 0) {
        s++;
      } else if (cnt > 0) {
        s += 2;
        cnt = 0;
      }
    }
  }
  cout << s;
  return 0;
}
