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:
// Don't place your source in a package
import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;



// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

        long Long() {
            return Long.parseLong(next());
        }

        String Str(){
            return next();
        }
    }


    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        //reading /writing file
        //Scanner sc=new Scanner(new File("input.txt"));
        //PrintWriter pr=new PrintWriter("output.txt");


        int T=1;
        for(int t=0;t<T;t++){
            String s=Str();
            Solution sol=new Solution(out);
            sol.solution(s);
        }
        out.close();

    }

    public static int[] Arr(int n){
        int A[]=new int[n];
        for(int i=0;i<n;i++)A[i]=Int();
        return A;
    }
    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}








class Solution{
    PrintWriter out;
    int INF=Integer.MAX_VALUE;
    public Solution(PrintWriter out){
        this.out=out;
    }


    public void solution(String s){
        if(s.length()<2){
            out.println(-1);return;
        }
        //25 50 75 00
        int res=Integer.MAX_VALUE;
        char A[]=s.toCharArray();
        int n=A.length;

        for(int i=0;i<n-2;i++){
            for(int j=i+1;j<n-1;j++){
                if(A[i]=='2'&&A[j]=='5'){
                    res=Math.min(res,check(s,i,j));
                }
            }
        }

        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n-1;j++){
                if(A[i]=='5'&&A[j]=='2'){
                    res=Math.min(res,check(s,j,i));
                }
            }
        }
        //System.out.println(res);


        for(int i=0;i<n-2;i++){
            for(int j=i+1;j<n-1;j++){
                if(A[i]=='5'&&A[j]=='0'){
                    res=Math.min(res,check(s,i,j));
                }
            }
        }

        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n-1;j++){
                if(A[i]=='0'&&A[j]=='5'){
                    res=Math.min(res,check(s,j,i));
                }
            }
        }

        //System.out.println(res);

        for(int i=0;i<n-2;i++){
            for(int j=i+1;j<n-1;j++){
                if(A[i]=='7'&&A[j]=='5'){
                    res=Math.min(res,check(s,i,j));
                }
            }
        }

        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n-1;j++){
                if(A[i]=='5'&&A[j]=='7'){
                    res=Math.min(res,check(s,j,i));
                }
            }
        }

        //System.out.println(res);

        for(int i=0;i<n-2;i++){
            for(int j=i+1;j<n-1;j++){
                if(A[i]=='0'&&A[j]=='0'){
                    res=Math.min(res,check(s,i,j));
                }
            }
        }

        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n-1;j++){
                if(A[i]=='0'&&A[j]=='0'){
                    res=Math.min(res,check(s,j,i));
                }
            }
        }

        //System.out.println(res);

        for(int i=0;i<n-1;i++){
            if((A[i]=='2'&&A[n-1]=='5')||(A[i]=='5'&&A[n-1]=='0')||A[i]=='7'&&A[n-1]=='5'||(A[i]=='0'&&A[n-1]=='0')){
                res=Math.min(res,check(s,i,n-1));
            }
        }

        for(int i=0;i<n-1;i++){
            if((A[i]=='5'&&A[n-1]=='2')||(A[i]=='0'&&A[n-1]=='5')||A[i]=='5'&&A[n-1]=='7'||(A[i]=='0'&&A[n-1]=='0')){
                //if(A[i+1]!='0')res=Math.min(res,n-i-1);
                int cnt=0;
                char B[]=s.toCharArray();
                for(int j=i;j<n-1;j++){
                    char t=B[j];
                    B[j]=B[j+1];
                    B[j+1]=t;
                    cnt++;
                }

                for(int j=0;j<n-2;j++){
                    if(B[j]!='0'){
                        res=Math.min(res,cnt+j);
                        break;
                    }
                }
                if(s.length()==2)res=Math.min(res,1);
            }
        }



        if((A[n-2]=='2'&&A[n-1]=='5')||(A[n-2]=='5'&&A[n-1]=='0')||(A[n-2]=='7'&&A[n-1]=='5')||(A[n-2]=='0'&&A[n-1]=='0')){
            res=0;
        }

        
        if(res==INF)out.println(-1);
        else out.println(res);
    }

    public int check(String s,int l,int r){
        char A[]=s.toCharArray();
        int res=0;
        for(int i=r;i<A.length-1;i++){
            char t=A[i];
            A[i]=A[i+1];
            A[i+1]=t;
            res++;
        }

        if(l>r)l--;
        for(int i=l;i<A.length-2;i++){
            char t=A[i];
            A[i]=A[i+1];
            A[i+1]=t;
            res++;
        }

        int n=A.length;
        boolean found=false;
        for(int i=0;i<n-2;i++){
            if(A[i]!='0'){
                found=true;
                res+=i;
                break;
            }
        }

        if(!found)res=Integer.MAX_VALUE;
        return res;
    }

}








/*
                             ;\
                            |' \
         _                  ; : ;
        / `-.              /: : |
       |  ,-.`-.          ,': : |
       \  :  `. `.       ,'-. : |
        \ ;    ;  `-.__,'    `-.|
         \ ;   ;  :::  ,::'`:.  `.
          \ `-. :  `    :.    `.  \
           \   \    ,   ;   ,:    (\
            \   :., :.    ,'o)): ` `-.
           ,/,' ;' ,::"'`.`---'   `.  `-._
         ,/  :  ; '"      `;'          ,--`.
        ;/   :; ;             ,:'     (   ,:)
          ,.,:.    ; ,:.,  ,-._ `.     \""'/
          '::'     `:'`  ,'(  \`._____.-'"'
             ;,   ;  `.  `. `._`-.  \\
             ;:.  ;:       `-._`-.\  \`.
              '`:. :        |' `. `\  ) \
      -hrr-      ` ;:       |    `--\__,'
                   '`      ,'
                        ,-'


                      free bug dog
*/