#include <bits/stdc++.h>
int n, a[2000], ok, ok1, dem, dem1;
char b[2000];
int main() {
  scanf("%d", &n);
  ok = 0;
  ok1 = 0;
  dem = 0;
  dem1 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) dem++;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      ok++;
      ok1 = 1;
      dem1++;
    } else {
      if (dem1 == dem) {
        ok1 = 0;
        break;
      }
      if (ok1 == 1) {
        ok++;
        ok1 = 0;
      }
    }
  }
  printf("%d", ok);
}
