#include <bits/stdc++.h>
using namespace std;
int main() {
  int c = 0, x;
  bool arr[1000];
  cin >> x;
  for (int i = 0; i < x; i++) cin >> arr[i];
  int i = 0;
  while (i < x) {
    if (arr[i]) c++;
    if (arr[i] && arr[i + 1] && i + 1 < x)
      i++;
    else if (arr[i] && i + 1 < x)
      c++, i++;
    else
      i++;
  }
  if (c && !(arr[x - 1])) c--;
  cout << c;
}
