#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  bool open = false;
  int cnt = 0;
  int a[1020];
  vector<int> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] & 1) {
      q.push_back(i);
      cnt++;
    }
  }
  if (cnt <= 1) {
    cout << cnt;
    return 0;
  }
  int ans = 1;
  for (int i = 1; i < q.size(); i++)
    if (q[i] - 1 == q[i - 1])
      ans++;
    else
      ans += 2;
  cout << ans;
}
