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.*;


public class Main {
    public static class instance{
        int steps;
        String ss;
        instance(int i,String ss){
            this.steps=i;
            this.ss=ss;
        }

    }
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        Scanner S = new Scanner(System.in);
        BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter PW = new PrintWriter(new OutputStreamWriter(System.out));
        String n=S.next();
        //00,25,75,50
        int fisrt0=-1;
        int second0=-1;
        int fisrt2=-1;
        int fisrt7=-1;
        int fisrt5=-1;

        for (int i = n.length()-1; i>-1 ; --i) {
            if(n.charAt(i)=='0'||n.charAt(i)=='2'||n.charAt(i)=='5'||n.charAt(i)=='7'){
                if(n.charAt(i)=='0'&&fisrt0==-1){fisrt0=i;}
                else if(n.charAt(i)=='0'&&fisrt0!=-1&&second0==-1){second0=i;}
                else if(n.charAt(i)=='2'&&fisrt2==-1){fisrt2=i;}
                else if(n.charAt(i)=='5'&&fisrt5==-1){fisrt5=i;}
                else if(n.charAt(i)=='7'&&fisrt7==-1){fisrt7=i;}
            }
        }
        List<instance>posLans=new ArrayList<>();

        StringBuilder sb=new StringBuilder(n);

            sb=new StringBuilder(n);
            if(fisrt0!=-1&&second0!=-1){
                //convert to " "+"00"
                int f=fisrt0,s=second0;
                int steps=0;
                while(f!=n.length()-1){
                    char ff='0';
                    char ss=sb.charAt(f+1);
                    sb.setCharAt(f, ss);
                    sb.setCharAt(f+1, ff);
                    ++f;
                    ++steps;
                }
                while(s!=n.length()-2){
                    char ff='0';
                    char ss=sb.charAt(s+1);
                    sb.setCharAt(s, ss);
                    sb.setCharAt(s+1, ff);
                    ++s;
                    ++steps;
                }
                instance ansss=new instance(steps,sb.toString());
                posLans.add(ansss);
            }
            sb=new StringBuilder(n);
            if(fisrt0!=-1&&fisrt5!=-1){
                //convert to " "+"50"
                int f=fisrt0,s=fisrt5;
                int steps=0;
                if(f<s){--s;}
                while(f!=n.length()-1){
                    char ff='0';
                    char ss=sb.charAt(f+1);
                    sb.setCharAt(f, ss);
                    sb.setCharAt(f+1, ff);
                    ++f;
                    ++steps;
                }
                while(s!=n.length()-2){
                    char ff='5';
                    char ss=sb.charAt(s+1);
                    sb.setCharAt(s, ss);
                    sb.setCharAt(s+1, ff);
                    ++s;
                    ++steps;
                }
                instance ansss=new instance(steps,sb.toString());
                posLans.add(ansss);
            }
         sb=new StringBuilder(n);
        if(fisrt7!=-1&&fisrt5!=-1){
            //convert to " "+"75"
            int f=fisrt5,s=fisrt7;
            int steps=0;
            if(f<s){--s;}
            while(f!=n.length()-1){
                char ff='5';
                char ss=sb.charAt(f+1);
                sb.setCharAt(f, ss);
                sb.setCharAt(f+1, ff);
                ++f;
                ++steps;
            }
            while(s!=n.length()-2){
                char ff='7';
                char ss=sb.charAt(s+1);
                sb.setCharAt(s, ss);
                sb.setCharAt(s+1, ff);
                ++s;
                ++steps;
            }
            instance ansss=new instance(steps,sb.toString());
            posLans.add(ansss);
        }
        sb=new StringBuilder(n);
        if(fisrt2!=-1&&fisrt5!=-1){
            //convert to " "+"25"
            int f=fisrt5,s=fisrt2;
            int steps=0;
            if(f<s){--s;}
            while(f!=n.length()-1){
                char ff='5';
                char ss=sb.charAt(f+1);
                sb.setCharAt(f, ss);
                sb.setCharAt(f+1, ff);
                ++f;
                ++steps;
            }
            while(s!=n.length()-2){
                char ff='2';
                char ss=sb.charAt(s+1);
                sb.setCharAt(s, ss);
                sb.setCharAt(s+1, ff);
                ++s;
                ++steps;
            }
            instance ansss=new instance(steps,sb.toString());
            posLans.add(ansss);
        }
        if (posLans.isEmpty()){System.out.println(-1);System.exit(0);}
        int cur=Integer.MAX_VALUE;int min=Integer.MAX_VALUE;
        for (int i = 0; i < posLans.size() ; i++) {
            if(posLans.get(i).ss.charAt(0)=='0'){
                if(posLans.get(i).ss.length()>3){
                    int counter=0;
                    for (int j = 0; j < posLans.get(i).ss.length(); j++) {
                        if(posLans.get(i).ss.charAt(j)=='0'){++counter;}
                        else{break;}
                    }
                    cur=posLans.get(i).steps+counter;if(cur<min){min=cur;}
                }
            }
            else{
                cur=posLans.get(i).steps;if(cur<min){min=cur;}
            }


        }
       if(min==Integer.MAX_VALUE){System.out.println(-1);}
       else{System.out.println(min);}

    }



}