#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, i;
  cin >> n;
  int *arr = new int[n + 1]();
  int k = 0;
  bool b = false;
  for (i = 0; i < n;) {
    cin >> a;
    i++;
    if (a == 1) {
      arr[k]++;
      b = true;
    } else {
      if (i < n) {
        i++;
        cin >> a;
        if (a == 0) {
          if (b) {
            k++;
            b = false;
          }
        } else {
          if (b)
            arr[k] += 2;
          else {
            arr[k]++;
            b = true;
          }
        }
      }
    }
  }
  int ans = -1;
  for (i = 0; i < n; i++) {
    if (arr[i] == 0)
      break;
    else {
      ans++;
      ans += arr[i];
    }
  }
  if (ans == -1)
    cout << 0;
  else
    cout << ans;
  return 0;
}
