#include <bits/stdc++.h>
using namespace std;
int a[1001];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == 1 && a[i + 1] == 1) {
      ans++;
    } else if (a[i] == 1) {
      ans += 2;
    }
  }
  if (ans == 0) {
    cout << 0;
    return 0;
  }
  cout << ans - 1;
}
