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 javafx.util.Pair;

import javax.sound.midi.Sequence;
import java.util.*;
import java.io.*;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    public static void main(String args[]) throws IOException {
        OutputStream outputStream = System.out;
        Reader in = new Reader();
        PrintWriter out = new PrintWriter(outputStream);

        long n = in.nextLong();

        if (n % 25 == 0) {
            out.println(0);
            out.close();
            return;
        }

        if (n < 25) {
            out.println(-1);
            out.close();
            return;
        }

        int res = 0x3f3f3f3f;

        res = Math.min(res, go(n, 0, 0));
        res = Math.min(res, go(n, 2, 5));
        res = Math.min(res, go(n, 5, 0));
        res = Math.min(res, go(n, 7, 5));

        if (res == 0x3f3f3f3f) res = -1;

        out.println(res);
        out.close();
    }

    private static int go(long n, int i, int i1) {
        String t = String.valueOf(n);
        char[] s = t.toCharArray();
        int res = 0;

        for (int j = t.length() - 1; j >= 0; j--) {
            if (s[j] - '0' == i1) {
                for (int k = j; k + 1 < t.length(); k++) {
                    char temp = s[k];
                    s[k] = s[k + 1];
                    s[k + 1] = temp;
                    res++;
                }

                i1 = -1;
                break;
            }
        }

        for (int j = t.length() - 2; j >= 0; j--) {
            if (s[j] - '0' == i) {
                for (int k = j; k + 1 < t.length() - 1; k++) {
                    char temp = s[k];
                    s[k] = s[k + 1];
                    s[k + 1] = temp;
                    res++;
                }

                i = -1;
                break;
            }
        }

        if (s[0] == '0') {
            for (int j = 0; j + 2 < t.length(); j++) if (s[j] != '0') {
                res += j;
                s[0] = s[j];
                break;
            }
        }

        if (i != -1 || i1 != -1 || s[0] == '0') res = 0x3f3f3f3f;
        return res;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f), 32768);
            st = null;
        }

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

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

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

    private static class Sequence {
        int n;
        List<Integer> vec;

        public Sequence() {
            n = 0;
            vec = new ArrayList<>();
        }
    }
}