#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n], z = 0, sum = 0, i, j, m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      z = i;
      sum = sum + 1;
      break;
    }
  }
  if (z == 0) {
    cout << 0;
    return 0;
  }
  m = z;
  for (i = z + 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      if (i - m == 1)
        sum = sum + 1;
      else
        sum = sum + 2;
      m = i;
    }
  }
  cout << sum;
}
