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