#include using namespace std; typedef unsigned long long int n_t; static map memo_; 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 MoveBitsByK(n_t val, int k) { auto new_val = val; for (int i = 1; i < len_; ++i) { if (i < k) continue; auto ith_bit = val & (1 << i); if (!ith_bit) continue; new_val = new_val | (1 << (i - k)); } return new_val; } static int SolveMinRelocations(n_t val) { if (val == target_val_) return 0; auto iter(memo_.find(val)); if (iter != memo_.end()) return iter->second; auto res = numeric_limits::max(); for (int k = 1; k < len_; ++k) { auto new_val = MoveBitsByK(val, k); if (val == new_val) continue; res = min(res, SolveMinRelocations(new_val) + 1); } memo_.insert({val, res}); return res; } static bool IsRelocPossible(const string& s) { return s[0] == '1'; } int main() { ios_base::sync_with_stdio(false); 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; }