#include <bits/stdc++.h>
using namespace std;
int n, coun, f = 10001;
bool q[1001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> q[i];
    if (q[i]) {
      f = min(f, i);
    }
  }
  if (f <= n) coun++;
  for (int i = f; i <= n; i++) {
    if (q[i + 1]) {
      coun++;
    } else {
      for (int j = i + 2; j <= n; j++) {
        if (q[j]) {
          i = j - 1;
          coun += 2;
          break;
        }
      }
      continue;
    }
  }
  cout << coun;
  return 0;
}
