#include <bits/stdc++.h>
using namespace std;
bool compare(int a, int b) { return a > b; }
int main() {
  int n, a, index;
  cin >> n;
  vector<int> A;
  int temp;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    A.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    if (A[i] == 1) {
      count++;
      index = i;
      break;
    }
  }
  for (int i = index + 1; i < n; i++) {
    if (A[i] == 1 && A[i - 1] == 1)
      count++;
    else if (A[i] == 1 && A[i - 1] == 0)
      count += 2;
    else
      continue;
  }
  cout << count;
  return 0;
}
