

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Clockwork {


    public static void main(String[] args) {
        
        Scanner  sc = new Scanner(System.in);
        
        String digits = sc.nextLine();
        int n = digits.length();
        if (digits.charAt(0) == '0') {
            System.out.println("-1");
        } else {
            
            
            
            long best = Long.parseLong(digits, 2);
            int i = 0;
            
            boolean found = false;
            List<Long> bestSoFar = new ArrayList<>();
            bestSoFar.add(best);
            int bestBitCount = Long.bitCount(best);
            
            while (!found) {
                i++;
                
                if (bestBitCount == n) {
                    System.out.println("0");
                    break;
                }
                
                int bestBitsCountTmp = bestBitCount;                
                List<Long> bestSoFarNext = new ArrayList<>();
                        
                for (Long state : bestSoFar) {
                    
                    for (int K = 1; K <= n; K++) {
                    
                        long tmp = state >> K;
                        tmp |= state;
                        int tmpBitcount = Long.bitCount(tmp);

                        if (tmpBitcount == n) {
                            System.out.println(i);
                            found = true;
                            break;
                        }

                        if (tmpBitcount > bestBitsCountTmp) {
                            bestSoFarNext = new ArrayList<>();
                            bestSoFarNext.add(tmp);
                            bestBitsCountTmp = tmpBitcount;
                        } else if (tmpBitcount == bestBitsCountTmp) {
                            bestSoFarNext.add(tmp);
                        }
                    }                    
                    
                    if (found) {
                        break;
                    }
                }
                
                bestSoFar = bestSoFarNext;                
            }
        }
        
    }
    
}
