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