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.io.*;
import java.math.BigInteger;
import java.text.*;
public class Main {
    static long mod = 1000_000_007;
    static long mod1 = 998244353;
    static boolean fileIO = false;
    static boolean memory = true;
    static FastScanner f;
    static PrintWriter pw;
    static double eps = (double)1e-6;
    static int oo = (int)1e9;

    public static void solve()throws Exception {
        char s[] = f.next().toCharArray();
        char copy[] = s.clone();
        int cnt[] = new int[10];
        int n = s.length;

        for (char c : s) ++cnt[c - '0'];
        
        // For making 00
        int ans = oo;
        if (cnt[0] >= 2) {
            int idx = -1; int curr = 0;
            for (int j = n - 1; j >= 0; --j) {
                if (s[j] == '0') {
                    idx = j;
                    break;
                }
            }

            for (int j = idx; j + 1 < n; ++j) {
                char t = s[j];
                s[j] = s[j + 1];
                s[j + 1] = t;
                ++curr;
            }

            for (int j = n - 2; j >= 0; --j) {
                if (s[j] == '0') {
                    idx = j;
                    break;
                }
            }

            for (int j = idx; j + 2 < n; ++j) {
                char t = s[j];
                s[j] = s[j + 1];
                s[j + 1] = t;
                ++curr;
            }

            for (int j = 0; j < n; ++j) {
                if (s[j] != '0') break;
                ++curr;
            }
            ans = Math.min(ans , curr);
        }

        // For making 25

        if (cnt[2] > 0 && cnt[5] > 0) {
            int curr = 0;
            int pos5 = -1 , pos2 = -1;
            s = copy.clone();
            for (int j = n - 1; j >= 0; --j) {
                if (s[j] == '5') {
                    pos5 = j;
                    break;
                }
            }

            for (int j = pos5; j + 1 < n; ++j) {
                char t = s[j];
                s[j] = s[j + 1];
                s[j + 1] = t;
                ++curr;
            }

            for (int j = n - 2; j >= 0; --j) {
                if (s[j] == '2') {
                    pos2 = j;
                    break;
                }
            }

            for (int j = pos2; j + 2 < n; ++j) {
                char t = s[j];
                s[j] = s[j + 1];
                s[j + 1] = t;
                ++curr;
            }

            for (int j = 0; j < n; ++j) {
                if (s[j] != '0') break;
                ++curr;
            }
            ans = Math.min(ans , curr);
        }
        
        // For making 50

        if (cnt[5] > 0 && cnt[0] > 0) {
            int curr = 0;
            int pos5 = -1 , pos0 = -1;
            s = copy.clone();
            for (int j = n - 1; j >= 0; --j) {
                if (s[j] == '0') {
                    pos0 = j;
                    break;
                }
            }

            for (int j = pos0; j + 1 < n; ++j) {
                char t = s[j];
                s[j] = s[j + 1];
                s[j + 1] = t;
                ++curr;
            }

            for (int j = n - 2; j >= 0; --j) {
                if (s[j] == '5') {
                    pos5 = j;
                    break;
                }
            }

            for (int j = pos5; j + 2 < n; ++j) {
                char t = s[j];
                s[j] = s[j + 1];
                s[j + 1] = t;
                ++curr;
            }

            for (int j = 0; j < n; ++j) {
                if (s[j] != '0') break;
                ++curr;
            }
            ans = Math.min(ans , curr);
        }

        // For making 75
        if (cnt[7] > 0 && cnt[5] > 0) {
            int curr = 0;
            int pos5 = -1 , pos7 = -1;
            s = copy.clone();
            for (int j = n - 1; j >= 0; --j) {
                if (s[j] == '5') {
                    pos5 = j;
                    break;
                }
            }

            for (int j = pos5; j + 1 < n; ++j) {
                char t = s[j];
                s[j] = s[j + 1];
                s[j + 1] = t;
                ++curr;
            }

            for (int j = n - 2; j >= 0; --j) {
                if (s[j] == '7') {
                    pos7 = j;
                    break;
                }
            }

            for (int j = pos7; j + 2 < n; ++j) {
                char t = s[j];
                s[j] = s[j + 1];
                s[j + 1] = t;
                ++curr;
            }

            for (int j = 0; j < n; ++j) {
                if (s[j] != '0') break;
                ++curr;
            }
            ans = Math.min(ans , curr);
        }

        pn(ans == oo ? -1 : ans);
    }    
 
    public static void main(String[] args)throws Exception {
        if(memory) new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "", 1 << 28).start();
        else new Main().run();
    }
        
/******************************END OF MAIN PROGRAM*******************************************/
    void run()throws Exception {
        if (fileIO) {
            f = new FastScanner("");
            pw = new PrintWriter(System.out);
        }
        else {
            f = new FastScanner();
            pw = new PrintWriter(System.out);
            //fw = new FileWriter("!out.txt");
        }
        //pre();
        int t = 1;
        int tt = 1;
        while(t --> 0) {
            //fw.write("Case #" + (tt++) + ": ");
            //fw.write("\n");
            solve();
        }
        pw.flush(); 
        pw.close();
        //fw.close();  
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public FastScanner(String str) throws Exception {
            try {
                br = new BufferedReader(new FileReader("!a.txt"));
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
 
        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        public String next()throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        public int ni() throws IOException {return Integer.parseInt(next());}
 
        public long nl() throws IOException {return Long.parseLong(next());}
 
        public String nextLine() throws IOException {return br.readLine();}
 
        public double nd() throws IOException {return Double.parseDouble(next());}
 
    }
 
    public static void pn(Object... o) {for(int i = 0; i < o.length; ++i) pw.print(o[i] + (i + 1 < o.length ? " ": "\n"));}
    public static void p(Object... o) {for(Object obj : o) pw.print(obj + " ");}
    public static void pni(Object... o) {for(Object obj : o) pw.print(oo + " "); pw.println(); pw.flush();}
    public static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    public static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}
    public static long lcm(long a,long b){return (a*b/gcd(a,b));}
    public static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    public static int pow(int a,int b){int res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    public static long mpow(long a,long b, long m){long res=1;while(b>0){if((b&1)==1)res=((res%m)*(a%m))%m;b>>=1;a=((a%m)*(a%m))%m;}return res;}
    public static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    public static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    public static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    public static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    public static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    public static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    public static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    public static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    public static int gnv(char c){return Character.getNumericValue(c);}
    public static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    public static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    public static void sort(ArrayList<Integer> a){Collections.sort(a);}
}