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.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {

    final int cannot = 9999999;
    int n;

    void solve() throws IOException {
        String s = readString();
        long ans = cannot;
        n = s.length();

        char[] a = s.toCharArray();
        if (n >= 2) {
            for (int second = 0; second < n; second++) {
                ans = min(ans, moveSecond(a, second, -1));
            }
        }
        if (n >= 3) {
            for (int toStart = 0; toStart < n; toStart++) {
                ans = min(ans, moveToStart(a, toStart));
            }
        }
        if (ans == cannot) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
    }

    private long moveToStart(char[] a, int toStart) {
        a = a.clone();
        int r = move(a, toStart, 0);
        int mi = cannot;
        for (int second = 0; second < n; second++) {
            if (second == toStart) {
                continue;
            }
            mi = min(mi, moveSecond(a, second, 0));
        }
        return r + mi;
    }

    private int moveSecond(char[] a, int second, int toStart) {
        a = a.clone();
        int r = move(a, second, n - 1);
        if (a[0] == '0') {
            return cannot;
        }
        int mi = cannot;
        for (int first = 0; first < n - 1; first++) {
            if (first == toStart) {
                continue;
            }
            mi = min(mi, moveFirst(a, first));
        }
        return r + mi;
    }

    private int moveFirst(char[] a, int first) {
        a = a.clone();
        int r = move(a, first, n - 2);
        if (a[0] == '0') {
            return cannot;
        }
        if (Long.parseLong(new String(a)) % 25 != 0) {
            return cannot;
        }
        return r;
    }

    private int move(char[] a, int from, int to) {
        int r = abs(from-to);
        int d;
        if (from < to) {
            d = 1;
        } else {
            d = -1;
        }
        while (from != to) {
            char tmp = a[from];
            try {
                a[from] = a[from + d];
            } catch (Exception e) {
                e.printStackTrace();
            }

            a[from + d] = tmp;
            from += d;
        }
        return r;
    }

    //-------------------------------------------------

    final boolean ONLINE_JUDGE = !new File("input.txt").exists();

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    public void run() {
        Runnable run = () -> {
            try {
                long startTime = System.currentTimeMillis();
                Locale.setDefault(Locale.US);
                if (ONLINE_JUDGE) {
                    in = new BufferedReader(new InputStreamReader(System.in));
                    out = new PrintWriter(System.out);
                } else {
                    in = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter("output.txt");
                }
                tok = new StringTokenizer("");
                solve();
                in.close();
                out.close();
                long endTime = System.currentTimeMillis();
                long totalMemory = Runtime.getRuntime().totalMemory();
                long freeMemory = Runtime.getRuntime().freeMemory();
                System.err.println();
                System.err.println("Time = " + (endTime - startTime) + " ms");
                //System.err.println("Memory = " + ((totalMemory - freeMemory) / 1024) + " KB");
            } catch (Throwable e) {
                e.printStackTrace(System.err);
                System.exit(-1);
            }
        };
        new Thread(null, run, "run", 256 * 1024 * 1024).start();
    }

    String readString() {
        while (!tok.hasMoreTokens()) {
            String line;
            try {
                line = in.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            if (line == null) return null;
            tok = new StringTokenizer(line);
        }
        return tok.nextToken();
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    void debug(Object... o) {
        if (!ONLINE_JUDGE) {
            System.err.println(Arrays.deepToString(o));
        }
    }

    long binpow(int a, int n) {
        long r = 1;
        while (n > 0) {
            if ((n & 1) > 0) {
                r *= a;
            }
            a *= a;
            n /= 2;
        }
        return r;
    }

    static long gcd(long x, long y) {
        return y == 0 ? x : gcd(y, x % y);
    }

    public static void main(String[] args) {
        new Main().run();
    }
}