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