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