#include <bits/stdc++.h>
using namespace std;
const int Max = 1e3 + 110;
int a[Max];
int main() {
  bool mark = 0;
  int n, ans = 0, fi = Max, la = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i]) fi = min(fi, i);
  }
  a[n] = 0;
  for (int i = fi; i <= n; i++) {
    if (la && a[i])
      ans++;
    else if (a[i])
      ans++;
    else if (la)
      ans++;
    la = a[i];
  }
  cout << max(ans - 1, 0);
}
