#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0, i, s = 0;
  cin >> n;
  int d[100000] = {};
  for (i = 1; i <= n; i++) {
    cin >> d[i];
    if (d[i] == 0)
      ;
    else {
      if (s == 0) {
        s = 1;
        c++;
      } else if (d[i - 1] == 0)
        c += 2;
      else
        c++;
    }
  }
  cout << c;
  return 0;
}
