#include <bits/stdc++.h>
using namespace std;
const int INF = 2034567891;
const long long int INF64 = 1234567890123456789ll;
int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
long long int dp[1005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long int store = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      store = i;
      break;
    }
  }
  if (store == -1) {
    cout << "0";
    return 0;
  }
  dp[store] = 1;
  for (int i = store + 1; i <= n - 1; i++) {
    if (a[i] == 0)
      dp[i] = dp[i - 1];
    else if (a[i - 1] == 1)
      dp[i] = dp[i - 1] + 1;
    else
      dp[i] = dp[i - 1] + 2;
  }
  cout << dp[n - 1];
}
