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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class ProblemEDivisibilityBy25 {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long n = in.nextLong();
            ArrayList<Integer> digits = new ArrayList<>();
            long temp = n;
            while (temp != 0) {
                digits.add((int) (temp % 10));
                temp /= 10;
            }
            if (digits.size() == 1) {
                out.println(-1);
                return;
            }
            int op25 = Integer.MAX_VALUE, op75 = Integer.MAX_VALUE, op50 = Integer.MAX_VALUE, op100 = Integer.MAX_VALUE;
            int index = digits.indexOf(5);
            if (index != -1) {
                //apply logic for 25 and 75
                op25 = op75 = index;
                ArrayList<Integer> copy = new ArrayList<>(digits);
                while (index > 0) {
                    Integer t = copy.get(index);
                    copy.remove(index);
                    copy.add(--index, t);
                }
                index = copy.indexOf(2);
                op25 = calculate(copy, op25, index);
                copy = new ArrayList<>(digits);
                index = op75;
                while (index > 0) {
                    Integer t = copy.get(index);
                    copy.remove(index);
                    copy.add(--index, t);
                }
                //out.println(op75);
                index = copy.indexOf(7);
                op75 = calculate(copy, op75, index);
            }
            index = digits.indexOf(0);
            if (index != -1) {
                //apply logic for 50 and 100
                op50 = op100 = index;
                ArrayList<Integer> copy = new ArrayList<>(digits);
                while (index > 0) {
                    Integer t = copy.get(index);
                    copy.remove(index);
                    copy.add(--index, t);
                }
                index = copy.indexOf(5);
                op50 = calculate(copy, op50, index);
                copy = new ArrayList<>(digits);
                index = op100;
                while (index > 0) {
                    Integer t = copy.get(index);
                    copy.remove(index);
                    copy.add(--index, t);
                }
                if (digits.size() != 2) {
                    index = -1;
                    for (int i = 1; i < copy.size() - 1; i++) {
                        if (copy.get(i) == 0) {
                            index = i;
                            break;
                        }
                    }
                    op100 = calculate(copy, op100, index);
                } else op100 = Integer.MAX_VALUE;
            }
            //out.println("op25 "+op25+" op50 "+op50+" op75 "+op75+" op100 "+op100);
            if (op25 == Integer.MAX_VALUE && op50 == Integer.MAX_VALUE && op75 == Integer.MAX_VALUE && op100 == Integer.MAX_VALUE)
                out.println(-1);
            else out.println(Math.min(op25, Math.min(op50, Math.min(op75, op100))));
        }

        public int calculate(ArrayList<Integer> copy, int op, int index) {
            if (index != -1) {
                op += index - 1;
                while (index > 1) {
                    Integer t = copy.get(index);
                    copy.remove(index);
                    copy.add(--index, t);
                }
                if (copy.size() != 2) {
                    index = -1;
                    for (int i = copy.size() - 1; i > 1; i--) {
                        if (copy.get(i) != 0) {
                            index = i;
                            break;
                        }
                    }
                    if (index == -1) op = Integer.MAX_VALUE;
                    else op += copy.size() - index - 1;
                }
            } else op = Integer.MAX_VALUE;
            return op;
        }

    }

    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 nextLong() {
            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);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}

