#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[105];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int c = 0;
  for (int i = 0; i < n;) {
    if (a[i] == 1) {
      while (a[i] == 1 || a[i + 1] == 1) {
        c++;
        i++;
        if (i == n) break;
      }
    }
    i++;
  }
  cout << c << endl;
  return 0;
}
