Problem: You are given an integer n from 1 to 10^{18} without leading zeroes.

In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.

What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25.

Input

The first line contains an integer n (1 ≤ n ≤ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero.

Output

If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number.

Note that you can swap only adjacent digits in the given number.

Examples

Input

5071


Output

4


Input

705


Output

1


Input

1241367


Output

-1

Note

In the first example one of the possible sequences of moves is 5071 → 5701 → 7501 → 7510 → 7150.

Solution (in JAVA):

Solution:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package Round486;

import java.util.Scanner;

/**
 *
 * @author Hemant Dhanuka
 */
public class E {
    
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        
     //   for(int i=0;i<20;i++){
        Long n=s.nextLong();
        String num=n+"";
        
        char c[]=num.toCharArray();
        int ans=Integer.MAX_VALUE;
        ans=Math.min(ans,fun('0','0',c));
                c=num.toCharArray();
        ans=Math.min(ans,fun('2','5',c));
                        c=num.toCharArray();

        ans=Math.min(ans,fun('7','5',c));
                        c=num.toCharArray();

        ans=Math.min(ans,fun('5','0',c));
        
        if(ans==Integer.MAX_VALUE){
            System.out.println(-1);
        }else{
            System.out.println(ans);
        }
    //}
    }

    private static int fun(char n1, char n2, char[] c) {
        int n1Index=-1;
        int n2Index=-1;
        boolean n1Mila=false;
        boolean n2Mila=false;
        for(int i=c.length-1;i>=0;i--){
            if(n2Mila==false && c[i]==n2){
                n2Mila=true;
                n2Index=i;
            }
            else if(n1Mila==false && c[i]==n1){
                n1Mila=true;
                n1Index=i;
            }
        }
        
        if(n1Index==-1 || n2Index==-1){
            return Integer.MAX_VALUE;
        }
        else{
           boolean possible=false;
            int moves=0;
            if(n1=='0' && n2=='0'){
                moves=c.length-1-n2Index+c.length-2-n1Index;
                return moves;
            }else{
                
                if((n2Index==0 || n1Index==0) && c.length!=2){
                    
                if(n2Index>n1Index){
                    moves=c.length-1-n2Index;
                    swap(n2Index,c.length-1,c);
                    
                    for(int j=n1Index+1;j<=c.length-2;j++){
                        if(c[j]!='0'){
                            possible=true;
                            moves=moves+j-n1Index;
                            n1Index++;
                            moves=moves+c.length-2-n1Index;
                            break;
                        }
                    }
                }else{
                    moves=c.length-1-n1Index;
                    swap(n1Index,c.length-1,c);
                    
                    for(int j=n2Index+1;j<=c.length-2;j++){
                        if(c[j]!='0'){
                            possible=true;
                            moves=moves+j-n2Index;
                            n2Index++;
                            moves=moves+c.length-2-n2Index;
                            break;
                        }
                    }
                }
                
            }
                else{
                    possible=true;
                    moves=c.length-1-n2Index+c.length-2-n1Index;
                    
                    if(n2Index>n1Index){
                        c[c.length-1]=n2;
                    }
                    else{
                        c[c.length-1]=n1;

                    }
                }
                
                
            }
            
            if(possible){
                
                if(n1=='5' && n2=='0'){
                    if(c[c.length-1]=='5'){
                        moves++;
                    }
                }
                else{
                    if(c[c.length-1]!='5'){
                        moves++;
                    }
                }
                
            return moves;
            }
            else{
                return Integer.MAX_VALUE;
            }
        }
        
        
        
    }
    
    
    public static void swap(int startIndex,int lastIndex,char c[]){
        while(startIndex<=lastIndex-1){
            char c1=c[startIndex];
            c[startIndex]=c[startIndex+1];
            c[startIndex+1]=c1;
            
            
            startIndex++;
        }
    }
}