#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n + 2];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      int res = -1;
      for (int j = i - 1; j >= 1; j--) {
        if (a[j] == 1) {
          res = i - j;
          break;
        }
      }
      if (res == -1)
        sum++;
      else if (res > 2)
        sum += 2;
      else
        sum += res;
    }
  }
  cout << sum << endl;
  return 0;
}
