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

public class DivisibilityBy25 {

    public static void main(String args[]) throws IOException {
        FastReader in = new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Task.solve(in, out);
        out.close();
    }

    static class Task {

        public static void solve(FastReader in, PrintWriter out) {
            String s = in.next();
            char[] c = s.toCharArray();
            int n =c.length;
            int fz = -1, ff = -1;
            int ans = Integer.MAX_VALUE;
            for(int i=n-1;i>=0;i--){
                if(c[i]=='0'){
                    fz = Math.max(fz,i);
                }
                if(c[i]=='5'){
                    ff = Math.max(ff,i);
                }
            }

            if(ff==0 && fz ==1){
                if(n==4){
                    System.out.println(2*(n-2));
                    return;
                }
                for(int i=n-1;i>=0;i--){
                    if(n>4){
                        if(c[i]=='2' || c[i]=='7'){
                            if(i==3){
                                System.out.println(Math.min((2*(n-2)),(n-ff-1)+(n-i-3)+2));
                                return;
                            }else{
                                System.out.println(Math.min((2*(n-2)),(n-ff-1)+(n-i-1)+1));
                                return;
                            }

                        }
                    }

                }
                System.out.println(2*(n-2));
                return;

            }else if(ff==0){
                boolean flag = true;
                for(int i=1;i<=fz;i++){
                    if(c[i]!='0'){
                        flag = false;
                        break;
                    }
                }
//                System.out.println(flag);
                if(flag && fz!=-1){
                    if(fz == n-1){
                        System.out.println(0);
                        return;
                    }
                    c[fz] = c[fz+1];
                    int val = fz+1;
                    c [fz+1] = 0;
                    fz++;
                    for(int i=n-1;i>=0;i--){
                        if(c[i]=='2' || c[i]=='7'){
                            if(i>fz){
                                System.out.println(Math.min((n-fz-1+n-3+val),(val+n-2+n-i-1)));
                            }else{
                                System.out.println(n-fz-1+n-3+val);
                            }
                            return;
                        }
                    }
                }
            }
            if(ff!=-1){
                for(int i=n-1;i>=0;i--){
                    if(i==ff){
                        continue;
                    }
                    if(c[i]=='2' || c[i]=='7'){
//                        System.out.println("Point1");
                        if(i>ff){
                            ans = Math.min(ans,(n-ff-1)+(n-i-1));
                        }else{
                            ans = Math.min(ans,(n-ff-1)+(n-i-1)-1);
                        }
                    }
                }
            }

            if(fz!=-1){
                for(int i=n-1;i>=0;i--){
                    if(i==fz){
                        continue;
                    }
                    if(c[i]=='0' || c[i]=='5'){
//                        System.out.println("Point2");
                        if(i>fz){
                            ans = Math.min(ans,(n-fz-1)+(n-i-1));
                        }else{
                            ans = Math.min(ans,(n-fz-1)+(n-i-1)-1);
                        }
                    }
                }
            }
            if(ans == Integer.MAX_VALUE){
                System.out.println("-1");
            }else{
                System.out.println(ans);
            }

        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}