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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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
 *
 * @author Vadim Semenov
 */
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);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static final class TaskE {
        public void solve(int __, InputReader in, PrintWriter out) {
            String number = in.next();
            if (number.length() == 1) {
                out.println(-1);
            } else if (number.length() == 2) {
                int n = Integer.parseInt(number);
                out.println(n % 25 == 0 ? 0 : n == 57 || n == 52 ? 1 : -1);
            } else {
                int answer = Integer.MAX_VALUE;
                for (int last = 0; last < 1000; last += 25) {
                    String suffix = String.format("%03d", last);
                    answer = Math.min(answer, makeSuffix(number, suffix));
                }
                out.println(answer == Integer.MAX_VALUE ? -1 : answer);
            }
        }

        private int makeSuffix(String number, String suffix) {
            assert suffix.length() == 3;
            if (number.length() == 3 && suffix.charAt(0) == '0') return Integer.MAX_VALUE;
            int[] lastPosition = new int[suffix.length()];
            Arrays.fill(lastPosition, -1);
            for (int i = number.length(); i-- > 0; ) {
                for (int j = suffix.length(); j-- > 0; ) {
                    if (suffix.charAt(j) == number.charAt(i) && lastPosition[suffix.length() - 1 - j] == -1) {
                        lastPosition[suffix.length() - 1 - j] = i;
                        break;
                    }
                }
            }
            for (int i = 0; i < suffix.length(); ++i) {
                if (lastPosition[i] == -1) {
                    return Integer.MAX_VALUE;
                }
            }
            int answer = 0;
            for (int i = 0; i < lastPosition.length; ++i) {
                answer += number.length() - lastPosition[i] - 1;
                for (int j = 0; j < i; ++j) {
                    if (lastPosition[j] > lastPosition[i]) {
                        answer--;
                    }
                }
            }
            int next = 0;
            while (next < number.length() && contains(lastPosition, next)) {
                next++;
            }
            if (next == number.length()) return answer;
            int zeros = 0;
            while (next < number.length() && (number.charAt(next) == '0' || contains(lastPosition, next))) {
                if (number.charAt(next) == '0' && !contains(lastPosition, next)) {
                    zeros++;
                }
                next++;
            }
            return zeros > 0 && next == number.length() ? Integer.MAX_VALUE : (answer + zeros);
        }

        private boolean contains(int[] set, int item) {
            for (int elem : set) {
                if (elem == item) {
                    return true;
                }
            }
            return false;
        }

    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(readLine());
            }
            return tokenizer.nextToken();
        }

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}

