#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 500010;
int n, num[10005];
int ans;
int main() {
  ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  for (int i = 2; i < n; i++) {
    if (num[i - 1] == 1 && num[i + 1] == 1) num[i] = 1;
  }
  for (int i = 1; i <= n; i++) ans += num[i];
  cout << ans << endl;
  return 0;
}
