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.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 void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.readLong();
            if (n < 25) {
                out.println(-1);
                return;
            }

            int[] suffix = new int[]{0, 25, 50, 75};
            int ans = 100;
            for (int i = 0; i < suffix.length; i++) {
                char[] seq = (n + "").toCharArray();
                int m = seq.length;
                int v = suffix[i];
                int cnt = 0;
                if (seq[m - 1] - '0' != v % 10) {
                    for (int j = m - 2; j >= 0; j--) {
                        if (seq[j] - '0' == v % 10) {
                            for (int k = j; k < m - 1; k++) {
                                char t = seq[k];
                                seq[k] = seq[k + 1];
                                seq[k + 1] = t;
                            }
                            cnt += m - 1 - j;
                            break;
                        }
                    }
                }
                v /= 10;
                if (seq[m - 2] - '0' != v % 10) {
                    for (int j = m - 3; j >= 0; j--) {
                        if (seq[j] - '0' == v % 10) {
                            for (int k = j; k < m - 2; k++) {
                                char t = seq[k];
                                seq[k] = seq[k + 1];
                                seq[k + 1] = t;
                            }
                            cnt += m - 2 - j;
                            break;
                        }
                    }
                }
                if (seq[0] == '0') {
                    for (int j = 1; j < seq.length - 2; j++) {
                        if (seq[j] != '0') {
                            seq[0] = seq[j];
                            seq[j] = '0';
                            cnt += j;
                            break;
                        }
                    }
                }


                if (seq[0] != '0') {
                    long x = Long.parseLong(new String(seq));
                    if (x % 25 == 0) {
                        ans = Math.min(ans, cnt);
                    }
                }
            }

            out.println(ans == 100 ? -1 : ans);
        }

    }

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

        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++];
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}