#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, t = 0, c = 1, f = 1;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> b;
    if (b == 1 & f != 1) {
      t += (2 - c);
      c = 1;
    } else if (f != 1)
      c = 0;
    if (b == 1 & f == 1) {
      t++;
      f = 0;
    }
  }
  cout << t;
}
