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