#include using namespace std; int getK(string& input) { int startIndex; int endIndex; int maxZeros = 0; int start; int end; int zeroes = 0; for(int i = 0; i < input.size(); i++) { if(input[i] == '0') { if(zeroes == 0) start = i; zeroes++; if(i == input.size() - 1) { end = i; if(zeroes > maxZeros) { maxZeros = zeroes; endIndex = end; startIndex = start; } } } else { if(zeroes != 0) { end = i-1; if(zeroes > maxZeros) { maxZeros = zeroes; endIndex = end; startIndex = start; } } zeroes = 0; } } //cout << startIndex << " " << endIndex << " " << maxZeros << endl; int oneCount = 0; for(int i = startIndex - 1; i >= 0; i--) { if(input[i] == '1') { oneCount++; } else { break; } } return (maxZeros + oneCount) / 2; } int done(string& input) { for(int i = 0; i < input.size(); i++) { if(input[i] == '0') return 0; } return 1; } int main() { string input; getline(std::cin, input); if(input[0] == '0') { cout << (-1) << endl; return 0; } int len = input.size(); int rounds = 0; while(!done(input)) { int K = getK(input); //cout << "chose K: " << K << endl; for(int i = len-1; i >= 0; i--) { if(input[i] == '1') { if(i+K < len) { input[i+K] = '1'; } } } //cout << "updated input: " << input << endl; rounds++; } cout << rounds << endl; return 0; }