#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
void yn(bool ok) {
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int cnt = 0;
  int i = 0;
  while (i < n) {
    if (a[i] == 1) {
      ++cnt;
      ++i;
      while (i < n and a[i] == 1) ++cnt, ++i;
      vector<int>::iterator it = a.begin() + i;
      if (find(it, a.end(), 1) != a.end()) ++cnt;
    } else
      while (i < n and a[i] == 0) ++i;
  }
  cout << cnt << "\n";
  return 0;
}
