#include <bits/stdc++.h>
using namespace std;
int n, k, l, m, findex, c;
int a[10000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      k = i;
      c = 1;
      break;
    }
  }
  for (int i = k; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[j] == 1) {
        findex = j - i;
        if (findex == 1)
          c += 1;
        else
          c += 2;
        i = j - 1;
        break;
      }
    }
  }
  cout << c << endl;
}
