#include using namespace std; typedef unsigned long long int n_t; static const n_t kSep = -1; static int len_; static n_t target_val_; static n_t ConvertBitsToLong(const string& s) { n_t v = 0; n_t p = 1; for (int i = s.size() - 1; i >= 0; --i) { v += (s[i] - '0') * p; p *= 2; } return v; } static n_t RelocateBitsByK(n_t val, int k) { return val | (val >> k); } static int SolveMinRelocations(n_t val) { queue q; set used; int steps_no = 0; q.push(val); q.push(kSep); while (!q.empty()) { auto v = q.front(); q.pop(); if (v == kSep) { ++steps_no; q.push(kSep); continue; } if (v == target_val_) return steps_no; if (used.count(v) > 0) continue; used.insert(v); for (int k = 1; k < len_; ++k) { auto new_val = RelocateBitsByK(v, k); if (v == new_val) continue; q.push(new_val); } } return -1; } static bool IsRelocPossible(const string& s) { return s[0] == '1'; } int main() { string input; cin >> input; if (!IsRelocPossible(input)) { cout << "-1" << endl; return 0; } auto val = ConvertBitsToLong(input); len_ = input.size(); target_val_ = static_cast(pow(2, len_) - 1); cout << SolveMinRelocations(val) << endl; return 0; }