#include <bits/stdc++.h>
using namespace std;
long long a[1010];
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i]) a[i] += a[i - 1];
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++)
    if (a[i] && a[i + 1] == 0) ans += (a[i] + 1);
  if (ans) ans--;
  cout << ans << endl;
  return 0;
}
