#include <bits/stdc++.h>
using namespace std;
const int mn = 1005;
int n, v[mn];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int x = 0; x < n; ++x) cin >> v[x];
  int ans = 0;
  for (int x = 0; x < n; ++x) {
    if (v[x] == 0) continue;
    while (v[x] == 1 && x < n) ++ans, ++x;
    ++ans;
  }
  if (ans != 0) --ans;
  cout << ans << "\n";
  return 0;
}
