#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v;
  int num;
  int flag = 0;
  int position = -1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &num);
    if ((flag == 0) && (num == 1)) {
      position = i;
      flag++;
    }
    v.push_back(num);
  }
  int count = 0;
  if (position != -1) count = 1;
  int nextposition = 0;
  for (int i = position + 1; i < v.size(); i++) {
    if (v[i] == 1 && nextposition >= 1) {
      count += 2;
      nextposition = 0;
    } else if (v[i] == 1 && nextposition == 0) {
      count += 1;
      nextposition = 0;
    } else
      nextposition++;
  }
  printf("%d\n", count);
  return 0;
}
