#include #define endl '\n' using namespace std; const int MAXN = 1e5 + 5; int main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("freddy.in", "r", stdin); freopen("freddy.out", "w", stdout); int n; cin >> n; string s; cin >> s; int i = 0; int ans = 0; while (i < n) { while (s[i] == '0') i++; // int i = -1; bool notReady = false; // for (int j = 0; j < n; j++) // if (s[j] == '0' && i != -1) notReady = true; // else // if (s[j] == '1' && i == -1) // { // i = j; // } // if (!notReady) break; int cnt = 0; int start = i; ans++; // cerr << "_ " << i << endl; int j; for (j = i; j < n ; j++) { // cerr << "k"; if (s[j] == '1' ) { if (cnt == 2 ) { // cerr << i << " " << start << " " << j << endl; // cerr << s << endl; reverse(s.begin() + start, s.begin() + j-0); // cerr << s << endl; i = j; break; } cnt = 1; } else if (j == n-1) { // cerr << "e\n"; // cerr << i << " " << start << " " << j << endl; // cerr << s << endl; reverse(s.begin() + start, s.end()); // cerr << s << endl; i = j; break; } else if (s[j] == '0') cnt = 2; } i = j; // cerr << s << endl; // i++; } // cerr << s << endl; cout << ans-1 << endl; return 0; } /** 20 01010001100010011010 */