#include <bits/stdc++.h>
using namespace std;
int main() {
  int input, count = 0, n;
  bool isfirstone = false;
  cin >> n;
  int arr[1001];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int lastoneindex = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] == 1) {
      lastoneindex = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == 1) {
      isfirstone = true;
      count = count + 1;
    } else if (arr[i] == 0 && isfirstone && i < lastoneindex) {
      count = count + 1;
      isfirstone = false;
    }
  }
  cout << count;
  return 0;
}
