#include #define For(i, n) for (int i = 0; i <(n); i++) #define ForD(i, n) for (int i = (n) - 1; i >= 0; i--) using namespace std; typedef long long ll; typedef unsigned long long ull; int best = 1<<30; int n; void go(ull x, int cnt) { if (__builtin_popcountll(x) == n) { best = min(best, cnt); return; } if (cnt >= best || cnt > 5) { return; } for (int i = 1; i <= 20; i++) { ull y = x | (x >> i); go(y, cnt + 1); } } int main() { ios::sync_with_stdio(0); //0 string s; cin >> s; ull x = 0; n = s.size(); For(i, (int)s.size()) { x *= 2; x += (s[i] - '0'); } if (s[0] != '1') { cout << "-1\n"; return 0; } go(x, 0); if (best >= (1<<30)) { cout << "-1\n"; } else { cout << best << "\n"; } }