#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 50;
int a[maxn];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int ans = 0, t = 1, k = 1, j = 1;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i] == 1) ans++;
      if (a[i] == 1 && k) {
        k = 0;
        j = i;
      }
    }
    for (int i = j; i <= n; i++) {
      if (a[i] == 1 && t == 0) {
        ans++;
        t = 1;
      }
      if (a[i] == 0)
        t = 0;
      else
        t = 1;
    }
    cout << ans << endl;
  }
}
