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.


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tok;
    static boolean hasNext()
    {
        while(tok==null||!tok.hasMoreTokens())
            try{
                tok=new StringTokenizer(in.readLine());
            }
            catch(Exception e){
                return false;
            }
        return true;
    }
    static String next()
    {
        hasNext();
        return tok.nextToken();
    }
    static long nextLong()
    {
        return Long.parseLong(next());
    }
    static int nextInt()
    {
        return Integer.parseInt(next());
    }
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) {
        String s = next();
        String ss="";
        if (Long.valueOf(s)%25==0){
            out.println(0);
            out.flush();
            return;
        }

        for(int i=s.length()-1;i>=0;i--){
            ss+=s.charAt(i);
        }
        int a = ss.indexOf('0');
        int b = ss.indexOf('2');
        int c = ss.indexOf('5');
        int d = ss.indexOf('7');
        if (c==s.length()-1){
            int index=0;
            for(int i=1;i<=s.length();i++){
                if (s.charAt(i)=='0'){
                    index=i;
                }else
                    break;
            }
            //index保存了唯一首位5之后的连续0串下标
            int ans1 = 0;
            int t = 0;
            for(int i=0;t<2&&i<ss.length();i++){
                if (ss.charAt(i)=='0'){
                    t++;
                    ans1+=i;
                }
            }
            if (t==2){
                ans1-=1;
            }else {
                ans1=10000;
            }
            //上面尝试两个0
            if (a==-1&&b==-1&&d==-1){
                out.println(-1);
                out.flush();
                return;
            }//GG
            int min;
            if (a==-1){ a=25; }
            if (b==-1){ b=75; }
            if (d==-1){ d=100; }
            if (a<b&&a<d){ min = a; }else if (b<a&&b<d){ min = b; }else { min = d; }
            if (ss.charAt(min)=='0') {//最低位是0
                if (ans1!=10000){
                    out.println(ans1);
                }else {
                    out.println(-1);
                }
            }
            else if (a==25){
                out.println(min+s.length()-1);
            }
            else if(min+index==s.length()-2){//唯一能选的和0挨着
                if (ans1!=10000){
                    out.println(ans1);
                }else {
                    int cc = s.length()-1-index+s.length()-1-min-1-1+s.length()-2;
                    out.println(index+c+min<cc?index+c+min:cc);
                }
            }else {//没挨着
                int num1 = index+c+min;
                int num2 = ans1;
                out.println(num1<num2?num1:num2);
            }




        }
        else if (c==-1){
            int t = 0;
            int ans = 0;
            for(int i=0;t<2&&i<ss.length();i++){
                if (ss.charAt(i)=='0'){
                    t++;
                    ans+=i;
                }
            }
            if (t==2){
                out.println(ans-1);
            }else {
                out.println(-1);
            }
        }else {//有5
            if (a==-1&&b==-1&&d==-1){
                out.println(-1);
                out.flush();
                return;
            }
            int t = 0;
            int ans = 0;
            for(int i=0;t<2&&i<ss.length();i++){
                if (ss.charAt(i)=='0'){
                    t++;
                    ans+=i;
                }
            }
            if (t==2){
                ans-=1;
            }else {
                ans=10000000;
            }


            if (b==0||d==0){
                //最后一位是2/7
                out.println(ans<c?ans:c);
            }else if (a==0){
                out.println(ans<c-1?ans:c-1);
            }
            //全不是0
            else {
                int min;
                if (a==-1){
                    a=25;
                }
                if (b==-1){
                    b=75;
                }
                if (d==-1){
                    d=100;
                }
                if (a<b&&a<d){
                    min = a;
                }else if (b<a&&b<d){
                    min = b;
                }else {
                    min = d;
                }

                if (ss.charAt(min)=='0'){
                    if (min<c){
                        //0在5右边
                        out.println(ans<c+min-1?ans:c+min-1);
                    }else {
                        out.println(ans<c+min?ans:c+min);
                    }
                }else {
                    if (min<c){
                        out.println(ans<min+c?ans:min+c);
                    }else {
                        out.println(ans<min+c-1?ans:min+c-1);
                    }
                }
            }
        }
        out.flush();
    }
}
