#include using namespace std; #define ll long long #define ull unsigned long long ull pls(char* arr) { ull res = 0; for(ull i = 0; i < strlen(arr); i++) { res *= 2; res += arr[i] - '0'; } return res; } char arr[420]; int main() { cin >> arr; if(arr[0] == '0') { cout << "-1\n"; return 0; } ull bm = pls(arr); unordered_set s{}; s.insert(bm); queue oq{}; queue nq{}; oq.push(bm); ull steps = 1; ull len = strlen(arr); ull end = ((ull)1 << len) - 1; while(true) { if(oq.empty()) { swap(oq, nq); steps++; //if(oq.empty()) return 1; //cout << "steps:" << steps << endl; } bm = oq.front(); oq.pop(); //cout << bm << endl; if(bm == end) break; for(ull i = 0; i <= len; i++) { ull nw = bm | (bm >> i); //cout << "try:" << nw << endl; if(nw != bm && s.find(nw) == s.end()) { //cout << "insert:" << nw << endl; s.insert(nw); nq.push(nw); } } } cout << (steps-1) << endl; return 0; }