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.io.*;
import java.util.*;
import java.math.*;

public class E {
    public static boolean cycle;
    public static HashSet<Integer> nodeCount;
    public static HashSet<String> edgeCount;
    public static void main(String[] args) throws IOException {
        FastScanner fs=new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        // int T = 1;

        // int T=fs.nextInt();
        // for (int tt=0; tt<T; tt++) {
        // }
        StringBuilder s = new StringBuilder(fs.next());
        int n = s.length();

        int res = Integer.MAX_VALUE;
        for (int i=0; i<n; i++) {
            for (int j=0; j<n-1; j++) {
                
                StringBuilder sbt = new StringBuilder(s);
                int ii = i+1;
                int steps = 0;
                while (ii<=n-1) {
                    char next = sbt.charAt(ii);
                    char cur = sbt.charAt(ii-1);
                    sbt.setCharAt(ii,cur);
                    sbt.setCharAt(ii-1,next);
                    ii++;
                    steps++;
                }
                int jj = j+1;
                while (jj<=n-2) {
                    char next = sbt.charAt(jj);
                    char cur = sbt.charAt(jj-1);
                    sbt.setCharAt(jj,cur);
                    sbt.setCharAt(jj-1,next);
                    jj++;
                    steps++;
                }
                int k = 0;
                if (sbt.charAt(k)=='0') {
                    while (sbt.charAt(k)=='0') {
                        k++;
                        steps++;
                    }
                    int kk=k-1;
                    while (kk>=0) {
                        char prev = sbt.charAt(kk);
                        char cur = sbt.charAt(kk+1);
                        sbt.setCharAt(kk,cur);
                        sbt.setCharAt(kk+1,prev);
                        kk--;
                    }
                }
                // out.println("   "+sbt.toString());
                if (Long.parseLong(sbt.toString())%25==0) {
                    res = Math.min(res, steps);
                }
                // if (Long.parseLong(sbt.toString())==7150) {
                //     out.println("   "+steps);
                // }
                
            }
        }
        if (s.length()>=2) {
            if ((s.charAt(n-1)=='2'&&s.charAt(n-2)=='5')
                || (s.charAt(n-1)=='7'&&s.charAt(n-2)=='5')
                || (s.charAt(n-1)=='5'&&s.charAt(n-2)=='0')
                ) {
                res = 1;
            }
        }
        if (Long.parseLong(s.toString())%25==0) {
            res = 0;
        }
        out.println(res==Integer.MAX_VALUE?-1:res);
        

        out.close();
    }

    

    static final Random random=new Random();
    
    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort 
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }
    
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}