#include <bits/stdc++.h>
using namespace std;
long long ceiling(long long x, long long y) {
  if (x % y)
    return ((x / y) + 1);
  else
    return (x / y);
}
long long gcd(long long x, long long y) {
  return ((y == 0) ? x : gcd(y, x % y));
}
long long lcm(long long x, long long y) { return ((x * y) / gcd(x, y)); }
int arr[1007], cpy[1007];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, cnt = 0, one = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cpy[i] = arr[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    if (arr[i - 1] == 1 || arr[i] == 1) {
      cpy[i] = cpy[i - 1] + 1;
    } else
      cpy[i] = cpy[i - 1];
  }
  if (!arr[n - 1] && cpy[n - 1]) cpy[n - 1]--;
  cout << cpy[n - 1];
  return 0;
}
