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:
//package contests.CF988;

import java.io.PrintWriter;
import java.util.Scanner;

public class E {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        char[] arr = sc.next().toCharArray();
        if(arr.length == 2)
        {
            if((arr[0] == '2' || arr[0] == '7') && arr[1] == '5')
            {
                System.out.println(0);
                return;
            }
            else if(arr[0] == '5' && arr[1] == '0') {
                System.out.println(0);
                return;
            }
        }
        // 25
        int ans1 = 0;
        ans1 = calc(2, 5, arr.clone());
        // 50
        int ans2 = 0;
        ans2 = calc(5, 0, arr.clone());
        // 75
        int ans3 = 0;
        ans3 = calc(7, 5, arr.clone());
        // 00
        int ans4 = calc(0, 0, arr.clone());

        pw.println(Math.min(ans1, Math.min(ans2, Math.min(ans3, ans4))) > 10000?-1:Math.min(ans1, Math.min(ans2, Math.min(ans3, ans4))));

        pw.flush();
        pw.close();
    }

    static int nearst(int n, char[] arr)
    {
        int res = -1;
        for (int i = arr.length-1; i >= 0; i--) {
            if(arr[i] - '0' == n)
                return i;
        }
        return res;
    }

    static int nearst2(int n, char[] arr)
    {
        int res = -1;
        int cnt = 0;
        for (int i = arr.length-1; i >= 0; i--) {
            if(arr[i] - '0' == n)
                if(cnt == 0)
                    cnt++;
                else
                    return i;
        }
        return res;
    }

    static int calc(int x, int y, char[] arr){
        int a = nearst(x, arr);
        if(x == 0 && y == 0)
            a = nearst2(x, arr);
        int b = nearst(y, arr);
        if(a == -1 || b == -1)
            return 1000000;
        int ans = 0;
        if(b == 0){
            int nxt = 1;
            for (int i = 1; i < arr.length && arr[i] == '0'; i++)
                nxt = i+1;
            if(nxt == arr.length)
                return 1000000;
            for (int i = nxt; i > 0; i--) {
                char tmp = arr[i];
                arr[i] = arr[i-1];
                arr[i-1] = tmp;
                ans++;
            }
            b = 1;
        }
        for(int i = b; i < arr.length-1; i++){
            char tmp = arr[i];
            arr[i] = arr[i+1];
            arr[i+1] = tmp;
            ans++;
        }

        if(x == 0 && y == 0)
            a = nearst2(x, arr);
        else
            a = nearst(x, arr);
        if(a == 0){
            int nxt = 1;
            for (int i = 1; i < arr.length && arr[i] == '0'; i++)
                nxt = i+1;
            if(nxt == arr.length)
                return 1000000;
            for (int i = nxt; i > 0 && nxt != arr.length-1; i--) {
                char tmp = arr[i];
                arr[i] = arr[i-1];
                arr[i-1] = tmp;
                ans++;
                a = 1;
            }
        }
        for(int i = a; i < arr.length-2; i++){
            char tmp = arr[i];
            arr[i] = arr[i+1];
            arr[i+1] = tmp;
            ans++;
        }
        return ans;
    }
}