#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, ctr = 0, j;     int arr[1000];     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     for (i = 0; i < n; i++)       if (arr[i] == 1) break;     if (i == n) {       cout << 0;       return 0;     }     for (j = n - 1; j >= 0; j--)       if (arr[j] == 1) break;     if (i == j) {       cout << 1;       return 0;     }     ctr = 1;     for (int k = i + 1; k <= j; k++) {       if (arr[k] == 1)         ctr++;       else if (arr[k] == 0 && arr[k - 1] == 1 && arr[k + 1] == 1)         ctr++;     }     cout << ctr;     return 0;   }   