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