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.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Rating2100_988E {
    //code written by a living bruh moment
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        int t = 1;
        for (int tt = 1; tt <= t; tt++) solver.solve(tt, in, out);
        out.close();
    }

    static class Task {

        public void solve(int tt, InputReader in, PrintWriter out) {
            String s = in.next();
            int[] a2 = new int[s.length()];
            if(s.length()==1){
                out.println(-1);
                return;
            }
            int zero = 0;
            int two = 0;
            int five = 0;
            int seven = 0;
            for(int i = 0; i<s.length(); i++){
                a2[i] = Integer.parseInt(s.substring(i,i+1));
                if(a2[i]==0) ++zero;
                if(a2[i]==2) ++two;
                if(a2[i]==5) ++five;
                if(a2[i]==7) ++seven;
            }
            int moves = (int) 1e9;
            if(zero>=2){
                int[] a = new int[a2.length];
                for(int i = 0; i<a2.length; i++){
                    int temp = a2[i];
                    a[i] = temp;
                }
                int temp = 0;
                int index = -1;
                for(int i = s.length()-1; i>=0; i--){
                    if (a[i] == 0) {
                        index = i;
                        break;
                    }
                }
                temp+=((s.length()-1)-index);
                index = -1;
                boolean check = false;
                for(int i = s.length()-1; i>=0; i--){
                    if (a[i] == 0) {
                        if(!check){
                            check = true;
                        }
                        else{
                            index = i;
                            break;
                        }
                    }
                }
                temp+=((s.length()-2)-index);
                moves = Math.min(moves,temp);
            }
            if(two>=1 && five>=1){
                int[] a = new int[a2.length];
                for(int i = 0; i<a2.length; i++){
                    int temp = a2[i];
                    a[i] = temp;
                }
                boolean doit = true;
                int temp = 0;
                int index = -1;
                for(int i = s.length()-1; i>=0; i--){
                    if (a[i] == 5) {
                        index = i;
                        break;
                    }
                }
                for(int i = index; i<s.length()-1; i++){
                    if(i==0 && a[1]==0){
                        boolean ahh = true;
                        for(int j = 1; j<s.length()-1; j++){
                            int t = a[j+1];
                            a[j+1] = a[j];
                            a[j] = t;
                            ++temp;
                            if(a[j]!=0){
                                ahh = false;
                                break;
                            }
                        }
                        if(ahh){
                            doit = false;
                            break;
                        }
                    }
                    int t = a[i+1];
                    a[i+1] = a[i];
                    a[i] = t;
                    ++temp;
                }
                index = -1;
                for(int i = s.length()-1; i>=0; i--){
                    if(a[i]==2){
                        index = i;
                        break;
                    }
                }
                for(int i = index; i<s.length()-2; i++){
                    if(i==0 && a[1]==0){
                        boolean ahh = true;
                        for(int j = 1; j<s.length()-2; j++){
                            int t = a[j+1];
                            a[j+1] = a[j];
                            a[j] = t;
                            ++temp;
                            if(a[j]!=0){
                                ahh = false;
                                break;
                            }
                        }
                        if(ahh){
                            doit = false;
                            break;
                        }
                    }
                    int t = a[i+1];
                    a[i+1] = a[i];
                    a[i] = t;
                    ++temp;
                }
                if(doit) moves = Math.min(moves,temp);
            }
            if(five>=1 && zero>=1){
                int[] a = new int[a2.length];
                for(int i = 0; i<a2.length; i++){
                    int temp = a2[i];
                    a[i] = temp;
                }
                boolean doit = true;
                int temp = 0;
                int index = -1;
                for(int i = s.length()-1; i>=0; i--){
                    if (a[i] == 0) {
                        index = i;
                        break;
                    }
                }
                for(int i = index; i<s.length()-1; i++){
                    if(i==0 && a[1]==0){
                        boolean ahh = true;
                        for(int j = 1; j<s.length()-1; j++){
                            int t = a[j+1];
                            a[j+1] = a[j];
                            a[j] = t;
                            ++temp;
                            if(a[j]!=0){
                                ahh = false;
                                break;
                            }
                        }
                        if(ahh){
                            doit = false;
                            break;
                        }
                    }
                    int t = a[i+1];
                    a[i+1] = a[i];
                    a[i] = t;
                    ++temp;
                }
                index = -1;
                for(int i = s.length()-1; i>=0; i--){
                    if(a[i]==5){
                        index = i;
                        break;
                    }
                }
                for(int i = index; i<s.length()-2; i++){
                    if(i==0 && a[1]==0){
                        boolean ahh = true;
                        for(int j = 1; j<s.length()-2; j++){
                            int t = a[j+1];
                            a[j+1] = a[j];
                            a[j] = t;
                            ++temp;
                            if(a[j]!=0){
                                ahh = false;
                                break;
                            }
                        }
                        if(ahh){
                            doit = false;
                            break;
                        }
                    }
                    int t = a[i+1];
                    a[i+1] = a[i];
                    a[i] = t;
                    ++temp;
                }
                if(doit) moves = Math.min(moves,temp);
            }
            if(seven>=1 && five>=1){
                int[] a = new int[a2.length];
                for(int i = 0; i<a2.length; i++){
                    int temp = a2[i];
                    a[i] = temp;
                }
                boolean doit = true;
                int temp = 0;
                int index = -1;
                for(int i = s.length()-1; i>=0; i--){
                    if (a[i] == 5) {
                        index = i;
                        break;
                    }
                }
                for(int i = index; i<s.length()-1; i++){
                    if(i==0 && a[1]==0){
                        boolean ahh = true;
                        for(int j = 1; j<s.length()-1; j++){
                            int t = a[j+1];
                            a[j+1] = a[j];
                            a[j] = t;
                            ++temp;
                            if(a[j]!=0){
                                ahh = false;
                                break;
                            }
                        }
                        if(ahh){
                            doit = false;
                            break;
                        }
                    }
                    int t = a[i+1];
                    a[i+1] = a[i];
                    a[i] = t;
                    ++temp;
                }
                index = -1;
                for(int i = s.length()-1; i>=0; i--){
                    if(a[i]==7){
                        index = i;
                        break;
                    }
                }
                for(int i = index; i<s.length()-2; i++){
                    if(i==0 && a[1]==0){
                        boolean ahh = true;
                        for(int j = 1; j<s.length()-2; j++){
                            int t = a[j+1];
                            a[j+1] = a[j];
                            a[j] = t;
                            ++temp;
                            if(a[j]!=0){
                                ahh = false;
                                break;
                            }
                        }
                        if(ahh){
                            doit = false;
                            break;
                        }
                    }
                    int t = a[i+1];
                    a[i+1] = a[i];
                    a[i] = t;
                    ++temp;
                }
                if(doit) moves = Math.min(moves,temp);
            }
            out.println(moves==(int)1e9?-1:moves);
        }
    }

    static void sort(int[] x) {
        shuffle(x);
        Arrays.sort(x);
    }

    static void sort(long[] x) {
        shuffle(x);
        Arrays.sort(x);
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.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() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public int[] nextInta(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public long[] nextLonga(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }

        public int[][] nextIntm(int n, int m) {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        public long[][] nextLongm(int n, int m) {
            long[][] a = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = nextLong();
                }
            }
            return a;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}