#include <bits/stdc++.h>
using namespace std;
const long long PR = 19260817;
int main() {
  int n, a[1005];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int cnt = 0, f = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      if (!f)
        cnt++;
      else
        f = 0;
      i++, cnt++;
      while (i < n && a[i]) i++, cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
