#include <bits/stdc++.h>
int main() {
  int arr[110];
  int n;
  std::cin >> n;
  int result = 0;
  for (int i = 0; i < n; i++) std::cin >> arr[i];
  int start = 0;
  while (start < n && arr[start] == 0) start++;
  for (int i = start; i < n; i++) {
    bool ok = true;
    for (int j = i; j < n; j++) {
      if (arr[j] == 1) {
        ok = false;
        break;
      }
    }
    if (ok) break;
    if (arr[i] == 0 && arr[i + 1] == 0) {
      while (i < n && arr[i] == 0) i++;
      i--;
      continue;
    }
    result++;
  }
  std::cout << result << '\n';
  return 0;
}
