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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EDivisibilityBy25 solver = new EDivisibilityBy25();
        solver.solve(1, in, out);
        out.close();
    }

    static class EDivisibilityBy25 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String num = in.next();
            int res = countMoves(num, "00");
            res = Math.min(res, countMoves(num, "25"));
            res = Math.min(res, countMoves(num, "50"));
            res = Math.min(res, countMoves(num, "75"));
            if (res == Integer.MAX_VALUE) {
                out.println(-1);
            } else {
                out.println(res);
            }
        }

        private int countMoves(String num, String toGet) {
            int res = 0;
            if (num.endsWith(toGet)) return 0;
            char[] arr = num.toCharArray();
            boolean found = true;
            for (int i = toGet.length() - 1; i >= 0; i--) {
                char cur = toGet.charAt(i);
                int curIdx = -1;
                for (int j = arr.length - 1 - (toGet.length() - 1 - i); j >= 0; --j) {
                    if (arr[j] == cur) {
                        curIdx = j;
                        break;
                    }
                }
                int to = arr.length - 1 - (toGet.length() - 1 - i);
                if (curIdx != -1) {
                    res += swap(arr, curIdx, to);
                } else {
                    found = false;
                    break;
                }
            }
            if (found) {
                int leftMostNonZero = 0;
                for (int i = 0; i < arr.length - toGet.length(); i++) {
                    if (arr[i] != '0') {
                        leftMostNonZero = i;
                        break;
                    } else {
                        leftMostNonZero = -1;
                    }
                }
                if (leftMostNonZero == -1) {
                    return Integer.MAX_VALUE;
                }
                return res + leftMostNonZero;
            } else {
                return Integer.MAX_VALUE;
            }
        }

        private int swap(char[] arr, int from, int to) {
            int res = 0;
            while (from != to) {
                char t = arr[from];
                arr[from] = arr[from + 1];
                arr[from + 1] = t;
                from++;
                res++;
            }
            return res;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}