#include <bits/stdc++.h>
using namespace std;
string s;
long long m, n, i, j, l, k, h, sum, x;
long long a[1000];
char c;
int main(int argc, char* argv[]) {
  cin >> n;
  sum = 0;
  cin >> a[0];
  if (a[0] == 1) sum++;
  for (i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1 && sum != 0) {
      if (a[i - 1] == 1)
        sum++;
      else
        sum += 2;
    } else if (a[i] == 1 && sum == 0)
      sum++;
  }
  cout << sum;
}
