#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, maxn = 1000, s = 0x3f3f3f3f;
  bool b[maxn + 5];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int cnt = 0, c = -s;
  for (int i = 0; i < n; i++) {
    if (b[i]) {
      if (c == -s) {
        c = i - 1;
      }
      cnt += min(2, i - c);
      c = i;
    }
  }
  if (cnt == 1) cout << 1;
  if (cnt == 0) cout << 0;
  if (cnt >= 2) cout << cnt;
  return 0;
}
