#include <bits/stdc++.h>
using namespace std;
int arr[1002];
int main() {
  int n, i, count = 0;
  cin >> n;
  for (i = 0; i < n; i++) cin >> arr[i];
  i = 0;
  while (arr[i] == 0 && i < n) i++;
  int flag = 1;
  for (; i < n; i++) {
    if (arr[i] == 1 && i < n) {
      flag = 1;
      count++;
    } else if (flag == 1) {
      flag = 0;
      count++;
    }
  }
  if (arr[n - 1] == 0 && count != 0) count--;
  cout << count;
  return 0;
}
