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.*;
import java.math.*;
import java.text.*;
import java.util.regex.*;

import java.awt.Point;
import java.awt.geom.Line2D;

public class Main {

    BufferedReader br;
    StringTokenizer st;

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    {
        st = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    void run() throws Exception {
        String s = nt();
        
        int[] frq = new int[10];
        for(int i=0; i<s.length(); i++)frq[s.charAt(i) - '0']++;
        
        int minSwaps = Integer.MAX_VALUE, temp;
        if(frq[2] >= 1 && frq[5] >= 1){
            temp = 0;
            
            List<Integer> list = getList(s);
            int ti = list.lastIndexOf(2);
            int fi = list.lastIndexOf(5);
            
            temp += list.size() - Math.max(ti, fi) - 1;
            Collections.rotate(list.subList(Math.max(ti, fi), list.size()), -1);
            //pl(list);
            temp += list.size() - Math.min(ti, fi) - 2;
            Collections.rotate(list.subList(Math.min(ti, fi), list.size() - 1), -1);
            //pl(list);
            if(list.get(list.size() - 1) == 2){Collections.swap(list, list.size() - 1, list.size() - 2); temp++;}
            //pl(list);
            if(list.get(0) == 0){
                for(int i=0; i<list.size(); i++){
                    if(list.get(i) == 0){
                        temp++;
                    }else{
                        Collections.rotate(list.subList(0, i + 1), 1);
                        break;
                    }
                }
            }
            //pl(list);
            if(list.get(0) != 0 && list.get(list.size() - 1) == 5 && list.get(list.size() - 2) == 2)minSwaps = Math.min(minSwaps, temp);
        }
        if(frq[5] >= 1 && frq[0] >= 1){
            temp = 0;
            
            List<Integer> list = getList(s);
            int fi = list.lastIndexOf(5);
            int zi = list.lastIndexOf(0);
            
            temp += list.size() - Math.max(zi, fi) - 1;
            Collections.rotate(list.subList(Math.max(zi, fi), list.size()), -1);
            //pl(list);
            temp += list.size() - Math.min(zi, fi) - 2;
            Collections.rotate(list.subList(Math.min(zi, fi), list.size() - 1), -1);
            //pl(list);
            if(list.get(list.size() - 1) == 5){Collections.swap(list, list.size() - 1, list.size() - 2); temp++;}
            //pl(list);
            if(list.get(0) == 0){
                for(int i=0; i<list.size(); i++){
                    if(list.get(i) == 0){
                        temp++;
                    }else{
                        Collections.rotate(list.subList(0, i + 1), 1);
                        break;
                    }
                }
            }
            //pl(list);
            if(list.get(0) != 0 && list.get(list.size() - 1) == 0 && list.get(list.size() - 2) == 5)minSwaps = Math.min(minSwaps, temp);
        }
        if(frq[7] >= 1 && frq[5] >= 1){
            temp = 0;
            
            List<Integer> list = getList(s);
            int si = list.lastIndexOf(7);
            int fi = list.lastIndexOf(5);
            
            temp += list.size() - Math.max(si, fi) - 1;
            Collections.rotate(list.subList(Math.max(si, fi), list.size()), -1);
            //pl(list);
            temp += list.size() - Math.min(si, fi) - 2;
            Collections.rotate(list.subList(Math.min(si, fi), list.size() - 1), -1);
            //pl(list);
            if(list.get(list.size() - 1) == 7){Collections.swap(list, list.size() - 1, list.size() - 2); temp++;}
            //pl(list);
            if(list.get(0) == 0){
                for(int i=0; i<list.size(); i++){
                    if(list.get(i) == 0){
                        temp++;
                    }else{
                        Collections.rotate(list.subList(0, i + 1), 1);
                        break;
                    }
                }
            }
            //pl(list);
            if(list.get(0) != 0 && list.get(list.size() - 1) == 5 && list.get(list.size() - 2) == 7)minSwaps = Math.min(minSwaps, temp);
        }
        if(frq[0] >= 2){
            temp = 0;
            List<Integer> list = getList(s);
            int fi = -1, si = -1;
            for(int i=list.size()-1; i>=0; i--){
                if(list.get(i) == 0){
                    if(si == -1){
                        si = i;
                    }else{
                        fi = i;
                        break;
                    }
                }
            }
            
            temp += list.size() - Math.max(si, fi) - 1;
            Collections.rotate(list.subList(Math.max(si, fi), list.size()), -1);
            //pl(list);
            temp += list.size() - Math.min(si, fi) - 2;
            Collections.rotate(list.subList(Math.min(si, fi), list.size() - 1), -1);
            //pl(list);
            if(list.get(0) == 0){
                for(int i=0; i<list.size(); i++){
                    if(list.get(i) == 0){
                        temp++;
                    }else{
                        Collections.rotate(list.subList(0, i + 1), 1);
                        break;
                    }
                }
            }
            //pl(list);
            if(list.get(0) != 0 && list.get(list.size() - 1) == 0 && list.get(list.size() - 2) == 0)minSwaps = Math.min(minSwaps, temp);
        }
        
        pl((minSwaps == Integer.MAX_VALUE) ? -1 : minSwaps);
    }
    
    List<Integer> getList(String num){
        List<Integer> list = new ArrayList<>(num.length());
        for(int i=0; i<num.length(); i++){list.add(num.charAt(i) - '0');}
        return list;
    }

    //Reader & Writer
    String nextToken() throws Exception {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine(), " ");
        }
        return st.nextToken();
    }

    String nt() throws Exception {
        return nextToken();
    }

    String ns() throws Exception {
        return br.readLine();
    }

    int ni() throws Exception {
        return Integer.parseInt(nextToken());
    }

    long nl() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nd() throws Exception {
        return Double.parseDouble(nextToken());
    }

    void p(Object o) {
        System.out.print(o);
    }

    void pl(Object o) {
        System.out.println(o);
    }
    
    int[] nia(int n) throws Exception {
        int[] a = new int[n];
        for(int i=0; i<n; i++)a[i] = ni();
        return a;
    }
    
    long[] nla(int n) throws Exception {
        long[] a = new long[n];
        for(int i=0; i<n; i++)a[i] = ni();
        return a;
    }
}