#include using namespace std; typedef long long ll; unordered_set st; const int N = 41; char s[N]; inline bool bit(ll x, int k) { return x & (1LL << k); } int main() { scanf("%s", s); ll k = 0, m = 1; for(char *c = s; *c; c++) { if(*c == '1') k |= m; m <<= 1; } int n = strlen(s); m--; if(!bit(k, 0)) { puts("-1"); return 0; } queue> q; q.push({ k, 0 }); st.insert(k); while(!q.empty()) { k = q.front().first; int d = q.front().second; q.pop(); if(k == m) { printf("%d\n", d); return 0; } for(int i = 1; i < n; i++) { if(!bit(k, i - 1)) break; ll x = k | (k << i) & m; if(!st.count(x)) { st.insert(x); q.push({ x, d + 1 }); } } } }