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:
//package com.company;

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));
//        Task tt = new Task();
//        tt.generate(22, 1000000, pw);
//        pw.close();
//        pw = new PrintWriter(new FileOutputStream("Test.out"));
        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
//        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
//        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {
        static final int cc = 1000;
        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            long a = sc.nextLong();
            String str = Long.toString(a);
            int n = str.length();
            int minSwap = cc;
            if (n == 2) {
                if (a % 25 == 0) {
                    pw.println(0);
                    return;
                } else {
                    long d = a / 10;
                    long c = a % 10;
                    a = c * 10 + d;
                    if (a % 25 == 0) {
                        pw.println(1);
                        return;
                    } else {
                        pw.println(-1);
                        return;
                    }
                }
            }
            for (int i = 0; i < n; i++) { // to end
                for (int j = 0; j < n; j++) { // to second to end
                    for (int k = 0; k < n; k++) { // to first
                        if (i == j || i == k || j == k) continue;
                        int swapI = n - 1 - i;
                        int swapJ = Math.abs(n - 2 - j);
                        int swapK = k;
                        int totel = swapI + swapJ + swapK;
                        if (i < k) totel--;
                        if (j < k) totel--;
                        if (j == n - 1) {
                            totel--;
                        } else if (j > i) {
                            totel++;
                        }
                        StringBuilder sb = new StringBuilder();
                        sb.append(str.charAt(k));
                        for (int l = 0; l < n; l++) {
                            if (l == i || l == j || l == k) continue;
                            sb.append(str.charAt(l));
                        }
                        sb.append(str.charAt(j));
                        sb.append(str.charAt(i));
                        if (isValid(sb.toString())) {
                            minSwap = Math.min(minSwap, totel);
                        }
                    }
                }
            }
            pw.println(minSwap == cc ? -1 : minSwap);
        }
        public boolean isValid(String str) {
            if (str.charAt(0) == '0') return false;
            if (str.length() < 2) return false;
            int n = str.length();
            if (str.charAt(n - 1) == '0') {
                char c = str.charAt(n - 2);
                return c == '0' || c == '5';
            } else if (str.charAt(n - 1) == '5') {
                char c = str.charAt(n - 2);
                return c == '2' || c == '7';
            }
            return false;

        }
    }


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

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

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

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

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

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

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