#include <bits/stdc++.h>
using namespace std;
int a[1001];
int c;
int ans;
int main() {
  int n;
  cin >> n;
  a[0] = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  vector<int> st, f;
  for (int i = 1; i <= n; i++) {
    if (!a[i - 1] && a[i]) st.push_back(i);
    if (a[i - 1] && !a[i]) f.push_back(i);
    if (i == n && a[i]) f.push_back(i + 1);
  }
  for (int i = 0; i < st.size(); i++) {
    ans += f[i] - st[i] + 1;
  }
  if (ans) ans--;
  cout << ans;
  return 0;
}
