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:
import java.util.*;
import java.math.*;
import java.io.*;
public class Solution{
    
    static void put(char[] c,int i,int fin){
        for(int j=i+1;j<=fin;j++){
            char r = c[j];
            c[j] = c[j-1];
            c[j-1] = r;
        }
    }
    
    static void remplir(String s,char[] c){
        int n = s.length();
        for(int i=0;i<n;i++){
            c[i] = s.charAt(i);
        }
    }
    
    static int solution(char[] c,char second,char first){
        
        int n = c.length;
        
        int posf = -1,poss = -1;
        for(int i=n-1;i>=0;i--){
            if(c[i]==first && posf==-1) posf = i;
            if(c[i]==second && poss==-1) poss = i;
        }
        if(posf==-1 || poss==-1) return 0;
        
        if(n==2) return 1;
        
        int nonzero = 0;
        for(int i=0;i<n;i++){
            if(c[i]!=0) nonzero++;
        }
        
        if(nonzero<3) return 0;
        
        int nb = 0;
        for(int i=0;i<n;i++){
            if(i!=posf && i!=poss && c[i]!='0'){
                nb += i;
                for(int j=i-1;j>=0;j--){
                    char r = c[j];
                    c[j] = c[j+1];
                    c[j+1] = r;
                }
                break;
            }
        }
        
        
        
        
        
        for(int i=n-1;i>=0;i--){
            if(c[i]==first){
                put(c,i,n-1);
                nb += n - i - 1;
                break;
            }
        }
        for(int i=n-2;i>=0;i--){
            if(c[i]==second){
                put(c,i,n-2);
                nb += n - i - 2;
                break;
            }
        }
        
        return nb;
        
        
    }
    
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        
        //int n = Integer.parseInt(st.nextToken());
        String s = st.nextToken();
        int n = s.length();
        
        char[] c = new char[n];
        for(int i=0;i<n;i++) c[i] = s.charAt(i);
        int max = 0;
        int nb = 0;
        
        if(n<2) System.out.println("-1");
        else if(s.substring(n-2,n).equals("00") || s.substring(n-2,n).equals("25") || s.substring(n-2,n).equals("50") || s.substring(n-2,n).equals("75"))
                    System.out.println("0");
        else{
            nb = 0;
            int fois = 0;
            for(int i=n-1;i>=0;i--){
                if(c[i]=='0'){
                    if(fois==0) put(c,i,n-1);
                    else put(c,i,n-2);
                    if(fois==0) nb += n - i - 1;
                    else nb += n - i - 2;
                    fois++;
                    if(fois==2) break;
                }
            }
            
            if(fois != 2) nb = 0;
            max = (int) Math.max(max,nb);
            
            remplir(s,c);
            nb = solution(c,'2','5');
            if(max==0) max = nb;
            else if(nb!=0) max = (int) Math.min(max,nb);

            remplir(s,c);
            nb = solution(c,'5','0');
            if(max==0) max = nb;
            else if(nb!=0) max = (int) Math.min(max,nb);

            remplir(s,c);
            nb = solution(c,'7','5');
            if(max==0) max = nb;
            else if(nb!=0) max = (int) Math.min(max,nb);

            if(max==0) System.out.println("-1");
            else System.out.println(max);
            
            
        }
        
        
        
    }
    
}