#include <bits/stdc++.h>
using namespace std;
long long n, x, p, a, i;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a += (2 - p) * x;
    p = x;
  }
  if (a - 1 > 0)
    cout << a - 1 << endl;
  else
    cout << 0 << endl;
}
