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.*;
public class etask{
    public static void main(String[] args) {
        
        Scanner s = new Scanner(System.in);
        long n = s.nextLong();
        String line = n+"";
        int length = line.length();

        int[] digits = new int[10];
        int[] n1 = new int[length];
        int[] n2 = new int[length];
        int[] n3 = new int[length];
        int[] n4 = new int[length];

        if(length <= 1){
            System.out.println(-1);
        }
        else{
            if(n%25 == 0){
                System.out.println(0);
            }
            else{
                int indx = length-1;
                while(n!=0){
                    int dig = (int)(n%10);
                    n1[indx] = dig;
                    n2[indx] = dig;
                    n3[indx] = dig;
                    n4[indx] = dig;
                    digits[dig]++;
                    n /= 10;
                    indx--;
                }

                int ans1 = 100;
                //50 check
                if(digits[5] >= 1&& digits[0] >= 1){
                    int ans = checkSteps(n1,0,5);
                    ans1 = Math.min(ans,ans1);
                    // System.out.println(ans);
                }

                if(digits[2] >= 1 && digits[5] >= 1){
                    int ans = checkSteps(n2,5,2);
                    ans1 = Math.min(ans,ans1);
                    // System.out.println(ans);   
                }

                if(digits[7] >= 1 && digits[5] >= 1){
                    int ans = checkSteps(n3,5,7);
                    ans1 = Math.min(ans,ans1);
                    // System.out.println(ans);
                }

                if(digits[0] >= 2){
                    int ans = checkSteps(n4,0,0);
                    ans1 = Math.min(ans,ans1);
                    // System.out.println(ans);
                }

                if(ans1 != 100)
                    System.out.println(ans1);
                else
                    System.out.println(-1);

            }
        }

        /*for(int i = 0;i < length;i++)
            System.out.print(n1[i]);
        System.out.println();*/

    }
    public static int checkSteps(int[] arr ,int dig1 , int dig2){
        int op1 = 0 , op2 = 0;
        int posdig1 = 0 , posdig2 = 0 , len = arr.length;
        for(int i = 0;i < arr.length;i++){
            if(arr[i] == dig1){
                posdig1 = i;
            }
        }
        int indx = posdig1;
        while(indx < arr.length-1){
            int temp = arr[indx];
            arr[indx] = arr[indx+1];
            arr[indx+1] = temp;
            indx++;
            op1++;
        }

        arr[arr.length-1] = -1;//place is taken 
        // print(arr);

        for(int i = 0;i < arr.length;i++){
            if(arr[i] == dig2){
                posdig2 = i;
            }
        }

        indx = posdig2;
        while(indx < arr.length-2){
            int temp = arr[indx];
            arr[indx] = arr[indx+1];
            arr[indx+1] = temp;
            indx++;
            op2++;
        }

        // print(arr);

        int noofzeroes = getZeroes(arr);
        return (op1+op2+noofzeroes);

    }

    public static void print(int[] arr){
        for(int i = 0;i < arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }

    public static int getZeroes(int[] arr){
        int result = 0;
        for(int i = 0;i < arr.length;i++){
            if(arr[i] == 0){
                result++;
            }
            else
                break;
        }
        return result;
    }
}