#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int a[maxn];
vector<int> G;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    G.clear();
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i] == 1) G.push_back(i);
    }
    int ans = 1, m = G.size();
    if (m == 0) {
      printf("0\n");
      continue;
    }
    if (m == 1) {
      printf("1\n");
      continue;
    }
    for (int i = 0; i < G.size() - 1; i++) {
      int u = G[i], v = G[i + 1];
      if (v - u > 2)
        ans += 2;
      else
        ans += v - u;
    }
    printf("%d\n", ans);
  }
  return 0;
}
