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