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.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import static java.lang.Math.*;
import java.util.concurrent.ThreadLocalRandom;

public class Sol implements Runnable {

    long mod = (long)1e9 + 7;

    int verifyUpdate(String s, int pos1, int pos2) {
        char c[] = s.toCharArray();

        int steps = 0;

        if(pos1 > pos2) pos1--;

        // change pos2
        for(int i=pos2;i<s.length()-1;i++) {
            char C = c[i];
            c[i] = c[i + 1];
            c[i + 1] = C;
            steps++;
        }

        // change pos1
        for(int i=pos1;i<s.length()-2;i++) {
            char C = c[i];
            c[i] = c[i + 1];
            c[i + 1] = C;
            steps++;
        }

        if(c[0] == '0') {
            int pos = -1;
            for(int i=1;i<c.length-2;i++) {
                if(c[i] != '0') {
                    pos = i;
                    break;
                }
            }

            if(pos == -1) return -1;
            steps += pos;
        }

        return steps;
    }

    void solve(InputReader in, PrintWriter w) {

        long n = in.nextLong();
        String s = Long.toString(n);

        int min = Integer.MAX_VALUE;

        if(s.contains("2") && s.contains("5")) {
            int step2 = -1, step5 = -1;

            for(int i=s.length()-1;i>=0;i--) {
                if(s.charAt(i) == '2' && step2 == -1) step2 = i;
                if(s.charAt(i) == '5' && step5 == -1) step5 = i;
            }

            int steps = verifyUpdate(s, step2, step5);

            if(steps != -1) min = min(min, steps);
        }

        if(s.contains("5") && s.contains("0")) {
            int step5 = -1, step0 = -1;

            for(int i=s.length()-1;i>=0;i--) {
                if(s.charAt(i) == '5' && step5 == -1) step5 = i;
                if(s.charAt(i) == '0' && step0 == -1) step0 = i;
            }

            int steps = verifyUpdate(s, step5, step0);

            if(steps != -1) min = min(min, steps);
        }

        if(s.contains("7") && s.contains("5")) {
            int step7 = -1, step5 = -1;

            for(int i=s.length()-1;i>=0;i--) {
                if(s.charAt(i) == '7' && step7 == -1) step7 = i;
                if(s.charAt(i) == '5' && step5 == -1) step5 = i;
            }

            int steps = verifyUpdate(s, step7, step5);

            if(steps != -1) min = min(min, steps);
        }

        int zero = 0;
        for(int i=0;i<s.length();i++) if(s.charAt(i) == '0') zero++;

        if(zero > 1) {
            int step0 = -1, step00 = -1;

            for(int i=s.length()-1;i>=0;i--) {
                if(s.charAt(i) == '0') {
                    if(step0 == -1) step0 = i;
                    else if(step00 == -1) step00 = i;
                }
            }

            int steps = verifyUpdate(s, step00, step0);

            if(steps != -1) min = min(min, steps);
        }

        if(min != Integer.MAX_VALUE) {
            w.println(min);
            return;
        }

        w.println("-1");
    }

    // ************* Code ends here ***************

    void init() throws Exception {
        //Scanner in;
        InputReader in;
        PrintWriter w;
        boolean online = false;

        String common_in_fileName = "\\in";
        String common_out_fileName = "\\out";
        int test_files = 0;

        for(int file_no = 0; file_no <= test_files; file_no++) {

            String x = "" + file_no;
            if (x.length() == 1) x = "0" + x;

            String in_fileName = common_in_fileName;// + "" + x;
            String out_fileName = common_out_fileName;// + "" + x;

            if (online) {
                //in = new Scanner(new File(in_fileName + ".txt"));
                in = new InputReader(new FileInputStream(new File(in_fileName + ".txt")));
                w = new PrintWriter(new FileWriter(out_fileName + ".txt"));
            } else {
                //in = new Scanner(System.in);
                in = new InputReader(System.in);
                w = new PrintWriter(System.out);
            }

            solve(in, w);
            w.close();
        }
    }

    public void run() {
        try {
            init();
        }
        catch(Exception e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }

    public static void main(String args[]) throws Exception {
        new Thread(null, new Sol(),"Sol",1<<28).start();
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private 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 String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c)) {
                c = read();
            }

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int 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 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 double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }
}