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.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class EDivisibilityBy25 {
        public void solve(int testNumber, FastScanner in, OutputWriter out) {
            String cc = in.next();
            if (Long.parseLong(cc) % 25 == 0) {
                out.println(0);
                return;
            }
            char[] ch = cc.toCharArray();
            ArrayList<Integer>[] tab = new ArrayList[10];
            for (int i = 0; i < 10; i++) {
                tab[i] = new ArrayList<>();
            }
            for (int i = 0; i < ch.length; i++) {
                if ("0257".contains(ch[i] + "")) {
                    tab[ch[i] - '0'].add(i);
                }
            }
            for (int i = 0; i < 10; i++) {
                tab[i].sort((i1, i2) -> i2 - i1);
            }
            int min = Integer.MAX_VALUE;
            if (tab[0].size() > 1) {
                min = Math.min(min, 2 * ch.length - 3 - tab[0].get(0) - tab[0].get(1));
            }

            if (tab[0].size() > 0 && tab[5].size() > 0) {
                char[] ch1 = ch.clone();
                int j = 0;
                if (tab[0].get(0) > tab[5].get(0)) {
                    int index = tab[5].get(0);
                    for (int i = tab[0].get(0); i < ch1.length - 1; i++) {
                        ch1[i] = ch1[i + 1];
                        j++;
                    }
                    ch1[ch1.length - 1] = '0';
                    boolean ok = true;
                    if (index == 0) {
                        int k = 1;
                        while (k < ch1.length && ch1[k] == '0') {
                            k++;
                        }
                        if (k > ch1.length - 2 && ch1.length > 2) ok = false;
                        if (k > 1) {
                            ch1[1] = ch1[k];
                            ch1[k] = '0';
                        }
                        j += k - 1;
                    }
                    if (ok) {
                        for (int i = index; i < ch1.length - 2; i++) {
                            ch1[i] = ch1[i + 1];
                            j++;
                        }
                        long b = Long.parseLong(String.copyValueOf(ch1));
                        if (String.valueOf(b).length() == cc.length())
                            min = Math.min(min, j);
                    }
                } else {
                    int index = tab[0].get(0);
                    for (int i = tab[5].get(0); i < ch1.length - 1; i++) {
                        ch1[i] = ch1[i + 1];
                        j++;
                    }
                    boolean ok = true;
                    if (index == 0) {
                        int k = 1;
                        while (k < ch1.length && ch1[k] == '0') {
                            k++;
                        }
                        if (k > ch1.length - 2 && ch1.length > 2) ok = false;
                        if (k > 1) {
                            ch1[1] = ch1[k];
                            ch1[k] = '0';
                        }
                        j += k - 1;
                    }
                    if (ok) {
                        for (int i = index; i < ch1.length - 1; i++) {
                            ch1[i] = ch1[i + 1];
                            j++;
                        }
                        long b = Long.parseLong(String.copyValueOf(ch1));
                        if (String.valueOf(b).length() == cc.length())
                            min = Math.min(min, j);
                    }
                }
            }

            if (tab[2].size() > 0 && tab[5].size() > 0) {
                char[] ch1 = ch.clone();
                int j = 0;
                if (tab[5].get(0) > tab[2].get(0)) {
                    int index = tab[2].get(0);
                    for (int i = tab[5].get(0); i < ch1.length - 1; i++) {
                        ch1[i] = ch1[i + 1];
                        j++;
                    }
                    boolean ok = true;
                    if (index == 0) {
                        int k = 1;
                        while (k < ch1.length && ch1[k] == '0') {
                            k++;
                        }
                        if (k > ch1.length - 2 && ch1.length > 2) ok = false;
                        if (k > 1) {
                            ch1[1] = ch1[k];
                            ch1[k] = '0';
                        }
                        j += k - 1;
                    }
                    if (ok) {
                        for (int i = index; i < ch1.length - 2; i++) {
                            ch1[i] = ch1[i + 1];
                            j++;
                        }
                        long b = Long.parseLong(String.copyValueOf(ch1));
                        if (String.valueOf(b).length() == cc.length())
                            min = Math.min(min, j);
                    }
                } else {
                    int index = tab[5].get(0);
                    for (int i = tab[2].get(0); i < ch1.length - 1; i++) {
                        ch1[i] = ch1[i + 1];
                        j++;
                    }
                    boolean ok = true;
                    if (index == 0) {
                        int k = 1;
                        while (k < ch1.length && ch1[k] == '0') {
                            k++;
                        }
                        if (k > ch1.length - 2 && ch1.length > 2) ok = false;
                        if (k > 1) {
                            ch1[1] = ch1[k];
                            ch1[k] = '0';
                        }
                        j += k - 1;
                    }
                    if (ok) {
                        for (int i = index; i < ch1.length - 1; i++) {
                            ch1[i] = ch1[i + 1];
                            j++;
                        }
                        long b = Long.parseLong(String.copyValueOf(ch1));
                        if (String.valueOf(b).length() == cc.length())
                            min = Math.min(min, j);
                    }
                }
            }

            if (tab[7].size() > 0 && tab[5].size() > 0) {
                char[] ch1 = ch.clone();
                int j = 0;
                if (tab[5].get(0) > tab[7].get(0)) {
                    int index = tab[7].get(0);
                    for (int i = tab[5].get(0); i < ch1.length - 1; i++) {
                        ch1[i] = ch1[i + 1];
                        j++;
                    }
                    boolean ok = true;
                    if (index == 0) {
                        int k = 1;
                        while (k < ch1.length && ch1[k] == '0') {
                            k++;
                        }
                        if (k > ch1.length - 2 && ch1.length > 2) ok = false;
                        if (k > 1) {
                            ch1[1] = ch1[k];
                            ch1[k] = '0';
                        }
                        j += k - 1;
                    }
                    if (ok) {
                        for (int i = index; i < ch1.length - 2; i++) {
                            ch1[i] = ch1[i + 1];
                            j++;
                        }
                        long b = Long.parseLong(String.copyValueOf(ch1));
                        if (String.valueOf(b).length() == cc.length())
                            min = Math.min(min, j);
                    }
                } else {
                    int index = tab[5].get(0);
                    for (int i = tab[7].get(0); i < ch1.length - 1; i++) {
                        ch1[i] = ch1[i + 1];
                        j++;
                    }
                    boolean ok = true;
                    if (index == 0) {
                        int k = 1;
                        while (k < ch1.length && ch1[k] == '0') {
                            k++;
                        }
                        if (k > ch1.length - 2 && ch1.length > 2) ok = false;
                        if (k > 1) {
                            ch1[1] = ch1[k];
                            ch1[k] = '0';
                        }
                        j += k - 1;
                    }
                    if (ok) {
                        for (int i = index; i < ch1.length - 1; i++) {
                            ch1[i] = ch1[i + 1];
                            j++;
                        }
                        long b = Long.parseLong(String.copyValueOf(ch1));
                        if (String.valueOf(b).length() == cc.length())
                            min = Math.min(min, j);
                    }
                }
            }
            if (min == Integer.MAX_VALUE) {
                out.println(-1);
            } else {
                out.println(min);
            }
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

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

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

    }
}