#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i < b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define pi pair<int, ll>
#define vi vector<int>
#define vvi vector<vi>
#define ALL(X) X.begin(),X.end()
#define fi first
#define se second
#define pb push_back
#ifndef DEBUG
#define endl (char)10
#endif
using namespace std;
using ll = long long;
using ld = long double;

ll M;
ll all;
int ans = 42;
int countx = 10000000;
int pc(ll x){
	int ansx = 0;
	while(x > 0){
		ansx += (x & 1);
		x /= 2;
	}
	return ansx;
}

void rek(int cans, ll nbit){
	if (countx == 0){
		return;
	}
	countx--;
	if (cans == ans) return;
	if (nbit == all) {
		ans = cans;
		return;
	}
	vector<pi> pos;
	FOR(i,1,40){
		ll nv = nbit | ((nbit << i) & all);
		pos.pb({pc(nv), nv});
	}
	sort(ALL(pos),[](pi a, pi b){
		if (a.fi != b.fi){
			return a.fi < b.fi;
		}
		return a.se > b.se;
		});
	cans++;
	FORD(i,38,0){
		rek(cans, pos[i].se);
	}
}

int main (){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll b = 0;
	string s;
	cin >> s;
	if (s[0] == '0'){
		cout << -1 << endl;
		return 0;
	}
	M = (1ll << s.size());
	all = M - 1;
	FORD(i,s.size()-1,0){
		b *= 2;
		b += s[i] - 48;
	}
	rek(0, b);
	
	cout << ans << endl;
}

