#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *arr = new int[n];
  int ans = 0;
  int *newarr = new int[n];
  int ind = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 1) {
      newarr[ind] = i;
      ind++;
    }
  }
  if (ind == 1) {
    cout << 1;
  } else {
    for (int i = 0; i < ind - 1; i++) {
      if (i == 0) {
        ans++;
      }
      ans += min(2, abs(newarr[i] - newarr[i + 1]));
    }
    cout << ans;
  }
  return 0;
}
