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.BufferedReader;
// import java.io.FileInputStream;
// import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.Arrays.fill;
import static java.util.Arrays.sort;

public class Main {
    private FastScanner in;
    private PrintWriter out;

    char[] s;
    int n;
    ArrayList<Integer>[] cnt;

    private void solve() throws IOException {
        s = in.next().toCharArray();
        n = s.length;
        if (n == 1) {
            out.println(-1);
            return;
        }

        cnt = new ArrayList[10];
        for (int i = 0; i < 10; i++) {
            cnt[i] = new ArrayList<>();
        }
        for (int i = n - 1; i >= 0; i--) {
            s[i] -= '0';
            cnt[s[i]].add(i);
        }

        long ans = Long.MAX_VALUE / 3;

        for (int[] i : new int[][]{{0, 0}, {5, 2}, {0, 5}, {5, 7}}) {
            if (i[1] == 0) {
                if (cnt[0].size() > 1) {
                    if (check(cnt[0].get(0), cnt[0].get(1)) != -1) {
                        ans = min(ans, (n - 1 - cnt[0].get(0)) + (n - 2 - cnt[0].get(1)) + check(cnt[0].get(0), cnt[0].get(1)));
                    }
                }
            } else {
                if (cnt[i[0]].size() > 0 && cnt[i[1]].size() > 0) {
                    if (check(cnt[i[0]].get(0), cnt[i[1]].get(0)) != -1) {
                        ans = min(ans, (n - 1 - cnt[i[0]].get(0)) + (n - 2 - (cnt[i[1]].get(0) - (cnt[i[0]].get(0) < cnt[i[1]].get(0) ? 1 : 0))) + check(cnt[i[0]].get(0), cnt[i[1]].get(0)));
                    }
                }
            }
        }

        out.println(ans == Long.MAX_VALUE / 3 ? -1 : ans);
    }

    private int check(int i, int j) {
        int cnt = 0;
        for (int k = 0; k < n; k++) {
            if (k != i && k != j) {
                if (s[k] != 0)
                    break;
                else
                    cnt++;
            }
        }
        return cnt == 0 ? 0 : n - 2 > cnt ? cnt : -1;
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

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

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next().replace(',', '.'));
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        solve();

        out.flush();
        out.close();
    }

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