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 java.io.*;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException {
//        out = new PrintWriter(new File("output.txt"));
//        br = new BufferedReader(new FileReader(new File("input.txt")));
        char[] p = next().toCharArray();
        int n = p.length;
        int[] a = new int[n];
        int ind_2 = -1;
        int ind_0 = -1;
        int cnt0 = 0;
        int ind_5 = -1;
        int ind_7 = -1;
        for (int i = 0; i < n; i++) {
            a[i] = p[i] - '0';
            if (a[i] == 0) {
                cnt0++;
                ind_0 = i;
            }
            if (a[i] == 2) ind_2 = i;
            if (a[i] == 5) ind_5 = i;
            if (a[i] == 7) ind_7 = i;
        }
        if (cnt0 >= 2 || (ind_0 != -1 && ind_5 != -1) || (ind_2 != -1 && ind_5 != -1) || (ind_7 != -1 && ind_5 != -1)) {
            int ans = Integer.MAX_VALUE;
//            25
            if (ind_2 != -1 && ind_5 != -1) {
                int can = 0;
                if (ind_5 < ind_2) {
                    int plus = 0;
                    if(ind_5 == 0){
                        for (int i = 1; i < n; i++) {
                            if(a[i] == 0)plus ++;
                            else break;
                        }
                    }
                    can += plus;
                    can += (n - ind_5 - 1);
                    can += (n - ind_2 - 1);
                } else {
                    int plus = 0;
                    if(ind_2 == 0){
                        for (int i = 1; i < n; i++) {
                            if(a[i] == 0)plus ++;
                            else break;
                        }
                    }
                    can += plus;
                    can += (n - ind_5 - 1);
                    can += (n - ind_2 - 2);
                }
                ans = Math.min(ans, can);
            }
//            00
            if (cnt0 >= 2) {
                int indf0 = -1;
                int inds0 = -1;
                for (int i = n - 1; i >= 0; i--) {
                    if (a[i] == 0) {
                        if (indf0 == -1) indf0 = i;
                        else {
                            inds0 = i;
                            break;
                        }
                    }
                }
                int can = n - indf0 - 1;
                can += (n - inds0 - 2);
                ans = Math.min(can, ans);
            }
//            50
            if (ind_5 != -1 && ind_0 != -1) {
                int can = 0;
                if (ind_0 < ind_5) {
                    can += (n - ind_0 - 1);
                    can += (n - ind_5 - 1);
                } else {
                    int plus = 0;
                    if(ind_5 == 0 && ind_0 != 1){
                        for (int i = 1; i < n; i++) {
                            if(a[i] == 0)plus ++;
                            else break;
                        }
                    }
                    can += plus;
                    can += (n - ind_0 - 1);
                    can += (n - ind_5 - 2);
                }
                ans = Math.min(ans, can);
            }
//          75
            if (ind_7 != -1 && ind_5 != -1) {
                int can = 0;
                if (ind_5 < ind_7) {
                    int plus = 0;
                    if(ind_5 == 0){
                        for (int i = 1; i < n; i++) {
                            if(a[i] == 0)plus ++;
                            else break;
                        }
                    }
                    can += plus;
                    can += (n - ind_5 - 1);
                    can += (n - ind_7 - 1);
                } else {
                    int plus = 0;
                    if(ind_7 == 0){
                        for (int i = 1; i < n; i++) {
                            if(a[i] == 0)plus ++;
                            else break;
                        }
                    }
                    can += plus;
                    can += (n - ind_5 - 1);
                    can += (n - ind_7 - 2);
                }
                ans = Math.min(ans, can);
            }
            out.println(ans);
        } else out.println(-1);
        out.close();
    }

    static boolean in(String a, String b) {
        int n = a.length();
        int m = b.length();
        for (int j = 0; j < m; j++) {
            int ind_j = j;
            int cnt = 0;
            while (cnt != n && ind_j != m && a.charAt(cnt) == b.charAt(ind_j)) {
                ind_j++;
                cnt++;
            }
            if (cnt == n) return true;
        }
        return false;
    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer in = new StringTokenizer("");


    public static String next() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}

class Point {
    int val;
    int ind;

    public Point(int val, int ind) {
        this.val = val;
        this.ind = ind;
    }
}