#include <bits/stdc++.h>
using namespace std;
long long i, n, k, c, m, mi, co, j;
long long a[1005];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    if (a[i] == 0)
      continue;
    else {
      k++;
      while (a[i + 1] == 1 && i + 1 <= n) {
        i++;
        k++;
      }
      k++;
    }
  }
  if (k > 0) k--;
  cout << k << endl;
  return 0;
}
