#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const long long inf = 1000000000000000010;
int n;
int input[110];
int main() {
  int n;
  scanf("%d", &n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> input[i];
  }
  bool flag = false;
  for (int i = 0; i < n; i++) {
    if (input[i] == 1) {
      flag = true;
      ans++;
    } else {
      if (flag == 0) continue;
      if (i >= n - 1 || input[i + 1] == 0) {
        flag = 0;
      } else
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
