#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, e, f, g, h;
  while (cin >> a) {
    int r[400];
    for (b = 1; b <= a; b++) {
      cin >> r[b];
    }
    c = 0;
    d = 0;
    e = 0;
    for (b = 1; b <= a; b++) {
      if (r[b] == 1) {
        c++;
        if (e == 1) {
          c++;
        }
        e = 0;
        d = 1;
      } else if (r[b] == 0 && d == 1) {
        e++;
      }
    }
    cout << c << endl;
  }
  return 0;
}
