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

public class Solve6 {

    public static void main(String[] args) {
        PrintWriter pw = new PrintWriter(System.out);
        new Solve6().solve(pw);
        pw.flush();
        pw.close();
    }

    public void solve(PrintWriter pw) {
        FastReader sc = new FastReader();
        long x = sc.nextLong();
        if (x % 25 == 0) {
            pw.println(0);
            return;
        }
        getDigits(x);
        n = digits.size();
        int ans = Integer.MAX_VALUE;
        int ind1 = getIndex(0, 0), ind2 = getIndex(0, ind1 + 1);
        if (check(ind1, ind2)) {
            ans = ind1 + ind2 - 1;
        }
        int ind3 = getIndex(5, 0);
        if (check(ind1, ind3)) {
            if (!(ind2 != n && ind3 == n - 1)) {
                if (ind1 < ind3) {
                    ans = Math.min(ans, ind1 + ind3 - 1);
                } else {
                    ans = Math.min(ans, ind1 + ind3);
                }
            }
        }
        int ind4 = Math.min(getIndex(2, 0), getIndex(7, 0));
        if (check(ind3, ind4)) {
            if (ind3 != n - 1 && ind4 != n - 1) {
                if (ind3 < ind4) {
                    ans = Math.min(ans, ind3 + ind4 - 1);
                } else {
                    ans = Math.min(ans, ind3 + ind4);
                }
            } else {
                int d = n - 2;
                if (ind1 != n) {
                    for (int i = n - 1; i >= 0; i--) {
                        if (digits.get(i) != 0 && i != ind3 && i != ind4) {
                            d = i;
                            break;
                        }
                    }
                }
                if (d != -1) {
                    int cost = n - 2 - d;
                    if (d < Math.min(ind3, ind4)) {
                        --cost;
                    }
                    if (ind3 < ind4) {
                        ans = Math.min(ans, cost + ind3 + ind4 - 1);
                    } else {
                        ans = Math.min(ans, cost + ind3 + ind4);
                    }
                }
            }
        }
        pw.println(ans == Integer.MAX_VALUE ? -1 : ans);
    }

    ArrayList<Integer> digits;
    int n;

    public boolean check(int ind1, int ind2) {
        return ind1 != n && ind2 != n;
    }

    public int getIndex(int d, int start) {
        for (int i = start; i < n; i++) {
            if (digits.get(i) == d) {
                return i;
            }
        }
        return n;
    }

    public void getDigits(long x) {
        digits = new ArrayList();
        while (x > 0) {
            digits.add((int) (x % 10));
            x /= 10;
        }
    }

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
            }
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            }
            return st.nextToken();
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

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

        public boolean hasNext() throws IOException {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            String s = br.readLine();
            if (s == null || s.isEmpty()) {
                return false;
            }
            st = new StringTokenizer(s);
            return true;
        }
    }
}
