#include <bits/stdc++.h>
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
int main() {
  int n, a[1005], ans;
  while (~scanf("%d", &n)) {
    ans = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    int work = -1;
    for (int i = 0; i < n; i++) {
      if (a[i] && i < n - 1 && a[i + 1]) {
        ans += 2;
        ++i;
        if (work == 0) {
          ++ans;
        }
        work = 1;
      } else if (a[i]) {
        if (work == 1) {
          ++ans;
          work = 0;
          continue;
        } else if (work == 0) {
          ++ans;
        }
        ans++;
        work = 0;
      } else if (!a[i]) {
        if (work != -1) work = 0;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
