#include using namespace std; #define PII pair #define VI vector #define VPII vector #define LL long long #define f first #define s second #define MP make_pair #define PB push_back #define LD long double #define endl '\n' #define ALL(c) (c).begin(), (c).end() #define SIZ(c) (int)(c).size() #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++) #define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--) #define ll LL #define mp MP #define pb PB #define st f #define nd s #define eb emplace_back const int inf = 1e9 + 7; const LL INF = 1e18L + 7; #define sim template ostream & operator << (ostream &p, pair x) {return p << "<" << x.f << ", " << x.s << ">";} sim> auto operator << (ostream &p, n y) -> typename enable_if::value, decltype(y.begin(), p)>::type {int o = 0; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";} void dor() {cerr << endl;} sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);} sim, class s> void mini(n &p, s y) {if (p > y) p = y;} sim, class s> void maxi(n &p, s y) {if (p < y) p = y;} #ifdef DEB #define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__) #else #define debug(...) #endif #define I(x) #x " =", (x), " " #define A(a, i) #a "[" #i " =", i, "] =", a[i], " " LL endd; LL res = 6; int n; set memo; void back(LL x, int r) { if(r >= res)return; if(x == endd) { mini(res, r); return; } if(memo.count(x))return; memo.insert(x); debug(x, r); vector V; FOR(i, 1, n) { V.PB(x | (x >> i)); } sort(ALL(V), [](LL x, LL y){return __builtin_popcount(x) > __builtin_popcount(y);}); for(auto i : V) back(i, r+1); } int main() { string s; cin >> s; if(s[0] == '0') { cout << -1 << endl; return 0; } LL x = 0; n = s.size(); REP(i, s.size()) { x *= 2; x += s[i] == '1'; } endd = (1LL << s.size()) - 1; back(x, 0); cout << res << endl; }