#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, x, y, cnt = 0, cnt1 = 0;
  int a[110];
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    if (a[i] == 1) {
      x = i;
      break;
    }
  }
  for (i = n - 1; i >= 0; i--) {
    if (a[i] == 1) {
      y = i;
      break;
    }
  }
  for (i = x; i <= y; i++) {
    if (a[i] == 1) cnt++;
    cnt1 = 0;
    if (a[i] == 0) {
      while (a[i + 1] == 0 && i + 1 < n) {
        cnt1++;
        i++;
      }
      if (cnt1 == 0) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
