#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, counter = 0, flag = 1;
  cin >> x;
  int arr[x];
  for (int i = 0; i < x; i++) cin >> arr[i];
  for (int i = 0; i < x; i++) {
    if (arr[i] == 1) {
      if (arr[i - 1] == 1 || flag)
        counter++, flag = 0;
      else
        counter += 2;
    }
  }
  cout << counter << endl;
  return 0;
}
