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 Main {
    public static int zero(char[] a) {
        int count = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != '0') {
                for (int j = i; j > 0;j--) {
                    a[j] ^= a[j - 1];
                    a[j - 1] ^= a[j];
                    a[j] ^= a[j - 1];
                    count++;
                    
                }
                return count;
            }
        }
        return count;
    }

    public static int solve(char a1, char b, char[] a) {
        int idx0 = 0;
        int idx1 = 0;
        int count = 0;
        // if ((a[a.length - 1] == b && a[a.length - 2] == a1)) {
        //           return count;
                
        // } else if (a[a.length - 1] == a1) {
        //         a[a.length - 1] ^= a[a.length - 2];
        //         a[a.length - 2] ^= a[a.length - 1];
        //         a[a.length - 1] ^= a[a.length - 2];
        //         count++;
        //         if (a[a.length - 1] == b && a[a.length - 2] == a1) {
        //           return count;
        //         }
        // }
            // The digit that will end up right most
            for (int i = 0; i < a.length; i++) {
                if (a[i] == b) {
                    idx1 = i;
                }
            }

            for (int i = idx1; i < a.length - 1; i++) {
                a[i] ^= a[i + 1];
                a[i + 1] ^= a[i];
                a[i] ^= a[i + 1];
                count++;
            }

            // The digit that will end up on the left
            for (int i = 0; i < a.length - 1; i++) {
                if (a[i] == a1) {
                    idx0 = i;
                }
            }
            
            for (int i = idx0; i < a.length - 2; i++) {
                a[i] ^= a[i + 1];
                a[i + 1] ^= a[i];
                a[i] ^= a[i + 1];
                count++;
            }
            if (a[0] == '0') {
                return count + zero(a);
            }

            return count;
    }

    public static void main(String[] args) {
        int min = 1000000;
        Scanner sc = new Scanner(System.in);
        int[] freq = new int[10];
        String s = sc.next();
        sc.close();
        char[] a = s.toCharArray();
        boolean case1 = false;
        boolean case2 = false;
        boolean case3 = false;
        boolean case4 = false;

        for (int i = 0; i < s.length(); i++) {
          int temp = Integer.valueOf(s.charAt(i) + "");
            freq[temp]++;
        }

        if (freq[0] >= 2) {
            case1 = true;
        }
        if (freq[7] >= 1 && freq[5] >= 1) {
            case2 = true;
        }
        if (freq[2] >= 1 && freq[5] >= 1) {
            case3 = true;
        }
        if (freq[0] >= 1 && freq[5] >= 1) {
            case4 = true;
        }

        
        if (case1) {
            char[] x = Arrays.copyOf(a, a.length);
            int count = solve('0', '0', x);
            min = Math.min(count, min);
        }

        if (case2) {
            char[] x = Arrays.copyOf(a, a.length);
            int count = solve('7', '5', x);
            min = Math.min(count, min);
        }

        if (case3) {
            char[] x = Arrays.copyOf(a, a.length);
            int count = solve('2', '5', x);
            min = Math.min(count, min);
        }

        if (case4) {
            char[] x = Arrays.copyOf(a, a.length);
            int count = solve('5', '0', x);
            min = Math.min(count, min);
        }
        
        if (min == 1000000) {
            System.out.println(-1);
            return;
        }

        System.out.println(min);
    }
}