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