#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[1007], i = 0, n, k = 0, j = 0;
  cin >> n;
  bool t = false;
  for (i = 0; i < n; i++) cin >> a[i];
  i = 0;
  while (i < n) {
    if (a[i] == 1) {
      k += 2;
      t = true;
      if (i != n - 1) {
        j = i + 1;
        while (a[j] == 1 && j < n) {
          k++;
          j++;
        }
        i = j - 1;
      }
    }
    i++;
  }
  if (n == 1 && a[0] != 0)
    cout << 1;
  else if (t == false)
    cout << k;
  else
    cout << k - 1;
  return 0;
}
