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.Arrays;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
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 final Set<String> multiples = Set.of("25", "50", "75", "00");

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] c = in.readLine().toCharArray();
            int best = (int) 1e9;
            for (int i = 0; i < c.length; i++) {
                for (int j = 0; j < c.length; ++j) {
                    if (i == j) continue;
                    int count = 0;
                    char[] x = Arrays.copyOf(c, c.length);

                    // shift to second-last position
                    for (int k = i; k < c.length - 1; k++) {
                        swap(x, k, k + 1);
                        count++;
                    }

                    // shift to last position
                    for (int k = j - (j > i ? 1 : 0); k < c.length - 2; k++) {
                        swap(x, k, k + 1);
                        count++;
                    }

                    // check for trailing zeroes
                    int zero = -1;
                    for (int k = 0; k < x.length; k++) {
                        if (x[k] != '0') {
                            zero = k;
                            break;
                        }
                    }

                    for (int k = zero; k > 0; k--) {
                        swap(x, k, k - 1);
                        count++;
                    }

                    if (multiples.contains("" + x[x.length - 2] + x[x.length - 1])) {
                        best = Math.min(best, count);
                    }
                }
            }

            out.println(best == (int) 1e9 ? -1 : best);
        }

        private void swap(char[] x, int k, int i) {
            char temp = x[k];
            x[k] = x[i];
            x[i] = temp;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

    }
}