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 sun.reflect.generics.tree.Tree;

import java.io.*;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.util.*;
public class l {
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////                                                                                                               /////////
////////                                                                                                               /////////
////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////
////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMMMM      MMMMMM      OOO      OOO        SSSS   SSS     EEEEEEEEEEEEE  /////////
////////   HHHH        HHHH  EEEEE           MMMM MMM  MMM MMMM    OOO          OOO    SSSS       SSS   EEEEE          /////////
////////   HHHH        HHHH  EEEEE           MMMM  MMMMMM  MMMM   OOO            OOO   SSSS             EEEEE          /////////
////////   HHHH        HHHH  EEEEE           MMMM          MMMM  OOO              OOO   SSSSSSS         EEEEE          /////////
////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO      SSSSSS       EEEEEEEEEEE    /////////
////////   HHHHHHHHHHHHHHHH  EEEEEEEEEEE     MMMM          MMMM  OOO              OOO         SSSSSSS   EEEEEEEEEEE    /////////
////////   HHHH        HHHH  EEEEE           MMMM          MMMM   OOO            OOO              SSSS  EEEEE          /////////
////////   HHHH        HHHH  EEEEE           MMMM          MMMM    OOO          OOO     SSS       SSSS  EEEEE          /////////
////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM      OOO      OOO        SSS    SSSS    EEEEEEEEEEEEE  /////////
////////   HHHH        HHHH  EEEEEEEEEEEEE   MMMM          MMMM         OOOOOO             SSSSSSS      EEEEEEEEEEEEE  /////////
////////                                                                                                               /////////
////////                                                                                                               /////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static long mod = (int) (1e9 + 7);
    static int n;
    static StringBuilder sol;

    static class pair implements Comparable<pair> {
        long val,dis;
        public pair( long x,long y) {
            val=x;dis=y;
        }

        public pair copy(){
            return new pair(val,dis);
        }
        public int compareTo(pair o) {
            return Long.compare(val,o.val);
        }
        public String toString(){
            return val+" "+dis;
        }
    }
    static class tri implements Comparable<tri>{
        int lef,righ,idx;
        tri(int a,int b,int c){
            lef=a;
            righ=b;
            idx=c;
        }
        public int compareTo(tri o) {
            if (lef==o.lef)return righ-o.righ;
            return lef-o.lef;
        }
        public String toString(){
            return lef+" "+righ+" "+idx;
        }
    }


    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        //FileWriter f = new FileWriter("C:\\Users\\Ibrahim\\out.txt");
        PrintWriter pw = new PrintWriter(System.out);
        char[]s= sc.nextLine().toCharArray();
        n=s.length;
        int id01=-1;
        int id02=-1;
        int id5=-1;
        int id2=-1;
        int id7=-1;
        for (int i =s.length-1;i>=0;i--){
            if (s[i]=='0'){
                if (id01==-1)id01=i;
                else if (id02==-1)id02=i;
            }
            if (s[i]=='2'&&id2==-1)id2=i;
            if (s[i]=='5'&&id5==-1)id5=i;
            if (s[i]=='7'&&id7==-1)id7=i;
        }
        int ans =Integer.MAX_VALUE;
        if (id01!=-1&&id02!=-1){
            ans=Math.min(ans,(n-1-id01)+(n-2-id02));
            //pw.println(ans);
        }
        if (id01!=-1&&id5!=-1){
            char[]mm =s.clone();
            int thi=0;
            for (int i =id01;i<s.length-1;i++){
                char tmp=mm[i];
                mm[i]=mm[i+1];
                mm[i+1]=tmp;
                thi++;
            }
            int c=id5;
            if (id01<id5)id5--;
            for (int i =id5;i<s.length-2;i++){
                char tmp=mm[i];
                mm[i]=mm[i+1];
                mm[i+1]=tmp;
                thi++;
            }
            id5=c;
            if (mm[0]=='0'){
                int d=-1;
                for (int i =0;i<mm.length-2;i++){
                    if (mm[i]!='0') {
                        d = i;
                        break;
                    }
                }
                if (d==-1)thi=Integer.MAX_VALUE;
                else thi+=d;
            }
            ans=Math.min(ans,thi);
        }
        if (id2!=-1&&id5!=-1){
            char[]mm =s.clone();
            int thi=0;
            for (int i =id5;i<s.length-1;i++){
                char tmp=mm[i];
                mm[i]=mm[i+1];
                mm[i+1]=tmp;
                thi++;
            }
            int c =id2;
            if (id5<id2)id2--;
            for (int i =id2;i<s.length-2;i++){
                char tmp=mm[i];
                mm[i]=mm[i+1];
                mm[i+1]=tmp;
                thi++;
            }
            id2=c;
            if (mm[0]=='0'){
                int d=-1;
                for (int i =0;i<mm.length-2;i++)if (mm[i]!='0'){
                    d=i;
                    break;
                }
                if (d==-1)thi=Integer.MAX_VALUE;
                else thi+=d;
            }
            ans=Math.min(ans,thi);
        }
        if (id7!=-1&&id5!=-1){
            char[]mm =s.clone();
            int thi=0;
            for (int i =id5;i<s.length-1;i++){
                char tmp=mm[i];
                mm[i]=mm[i+1];
                mm[i+1]=tmp;
                thi++;
            }
            int c =id7;
            if (id5<id7)id7--;
            for (int i =id7;i<s.length-2;i++){
                char tmp=mm[i];
                mm[i]=mm[i+1];
                mm[i+1]=tmp;
                thi++;
            }
            id7=c;
            if (mm[0]=='0'){
                int d=-1;
                for (int i =0;i<mm.length-2;i++){
                    if (mm[i]!='0'){
                        d=i;
                        break;
                    }
                }
                if (d==-1)thi=Integer.MAX_VALUE;
                else thi+=d;
            }
            ans=Math.min(ans,thi);
        }
        pw.println(ans==Integer.MAX_VALUE?-1:ans);
        pw.flush();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }
        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }
        public boolean ready() throws IOException {
            return br.ready();
        }

    }

}