#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int N;
  int A[100005];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
  }
  int i = 0;
  while (A[i] != 1) i++;
  int cnt = 0;
  int ans = 0;
  for (; i < N; i++) {
    if (A[i] == 1) {
      if (cnt == 1)
        ans += 2;
      else
        ans++;
      cnt = 0;
    } else {
      cnt++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
