#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 0, k = 0, a;
  cin >> a;
  int mass[a];
  for (int i = 0; i < a; i++) {
    cin >> mass[i];
    if (mass[i] == 1) t++;
  }
  for (int i = 0; i < a; i++)
    if (mass[i] == 1) k++;
  if (k == 0)
    cout << 0;
  else {
    k = 0;
    for (int i = 0; i < a; i++)
      if (mass[i] == mass[i + 1] && mass[i] == 1) k++;
    cout << (((t - 1) - k) * 2) + k + 1;
  }
}
