#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
  int n;
  while (cin >> n) {
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int sum = 0;
    bool b = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        sum++;
        b = 1;
      } else {
        if (i < n - 1 && b == 1 && a[i + 1] == 1) sum++;
        b = 0;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
