#include <bits/stdc++.h>
using namespace std;
int cla[110];
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  int c;
  int cnt0, cnt1;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (c == 1) {
      if (cnt0 == 1 && flag == 1) cnt++;
      flag = 1;
      cnt0 = 0;
      cnt++;
    } else {
      cnt0++;
    }
  }
  cout << cnt << endl;
  return 0;
}
