#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
const int M = 3e4 + 5;
const int mod = 1e9 + 7;
const int MAX_LOG = 16;
const int inf = 0x3f3f3f3f;
int readint() {
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  int res = 0;
  while (isdigit(c)) res = res * 10 + c - '0', c = getchar();
  return res;
}
int n;
int a[111];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  int t = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      t++;
      flag = 1;
    } else if (a[i] == 0 && a[i + 1] == 0) {
      flag = 0;
    } else if (a[i] == 0 && flag) {
      t++;
    }
  }
  printf("%d\n", t);
  return 0;
}
