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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class firstone {

    public static void main(String[] args) {

        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String s = in.readString();
        int first0 = -1;
        int second0 = -1;
        int first2 = -1;
        int first7 = -1;
        int first5 = -1;

        for (int i = s.length()-1 ; i>=0 ; i--)
        {
            if(s.charAt(i)=='0' || s.charAt(i)=='2' ||s.charAt(i) == '7'||s.charAt(i) == '5')
            {
                if(s.charAt(i) == '0' && first0 == -1){
                    first0 = i;
                }else if(s.charAt(i) == '0' && first0 != -1 && second0 == -1)
                {
                    second0 = i;
                }else if(s.charAt(i) == '2' && first2 == -1){
                    first2 = i;
                }else if(s.charAt(i) == '5' && first5 == -1 )
                {
                    first5 = i;
                }else if(s.charAt(i) == '7' && first7 == -1)
                {
                    first7 = i;
                }
            }

        }
        ArrayList<banatejao> letejao  = new ArrayList<>();

        StringBuilder banana = new StringBuilder(s);
        if(first0 !=-1 && second0 !=-1)  //Matlab "00" present hai khi na kahi
        {
            int first = first0;
            int second = second0;
            int steps = 0;
            while (first !=s.length() - 1)
            {
                char rep = '0';
                char mila = banana.charAt(first + 1);
                banana.setCharAt(first , mila);
                banana.setCharAt(first + 1 , rep);
                first++;
                steps++;
            }
            while (second != s.length() - 2)
            {
                char rep = '0';
                char mila = banana.charAt(second + 1);
                banana.setCharAt(second , mila);
                banana.setCharAt(second + 1 , rep);
                second++;
                steps++;
            }

            banatejao x = new banatejao(steps,banana.toString());
            letejao.add(x);
        }
         banana = new StringBuilder(s);
        if(first0 !=-1 && first5 !=-1)  //Matlab "50" present hai khi na kahi
        {
            int first = first0;
            int second = first5;
            int steps = 0;
            if(first<second){
                second --;
            }
            while (first !=s.length() - 1)
            {
                char rep = '0';
                char mila = banana.charAt(first + 1);
                banana.setCharAt(first , mila);
                banana.setCharAt(first + 1 , rep);
                first++;
                steps++;
            }
            while (second != s.length() - 2)
            {
                char rep = '5';
                char mila = banana.charAt(second + 1);
                banana.setCharAt(second , mila);
                banana.setCharAt(second + 1 , rep);
                second++;
                steps++;
            }

            banatejao x = new banatejao(steps,banana.toString());
            letejao.add(x);
        }
        banana = new StringBuilder(s);
        if(first7 !=-1 && first5 !=-1)  //Matlab "75" present hai khi na kahi
        {
            int first = first5;
            int second = first7;
            int steps = 0;
            if(first<second)
            {
                second-- ;
            }
            while (first !=s.length() - 1)
            {
                char rep = '5';
                char mila = banana.charAt(first + 1);
                banana.setCharAt(first , mila);
                banana.setCharAt(first + 1 , rep);
                first++;
                steps++;
            }
            while (second != s.length() - 2)
            {
                char rep = '7';
                char mila = banana.charAt(second + 1);
                banana.setCharAt(second , mila);
                banana.setCharAt(second + 1 , rep);
                second++;
                steps++;
            }

            banatejao x = new banatejao(steps,banana.toString());
            letejao.add(x);
        }
        banana = new StringBuilder(s);
        if(first2 !=-1 && first5 !=-1)  //Matlab "25" present hai khi na kahi
        {
            //out.println(first2 + " "+first5);
            int first = first5;
            int second = first2;
            int steps = 0;
            if(first < second)
            {
                second--;
            }
            while (first !=s.length() - 1)
            {
                char rep = '5';
                char mila = banana.charAt(first + 1);
                banana.setCharAt(first , mila);
                banana.setCharAt(first + 1 , rep);
                first++;
                steps++;
            }
            while (second != s.length() - 2)
            {
                char rep = '2';
                char mila = banana.charAt(second + 1);
                banana.setCharAt(second , mila);
                banana.setCharAt(second + 1 , rep);
                second++;
                steps++;
            }

            banatejao x = new banatejao(steps,banana.toString());
            letejao.add(x);
        }

        if(letejao.isEmpty()){
            out.println("-1");
            out.close();
            return;
        }
            int cur = Integer.MAX_VALUE;
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < letejao.size(); i++) {
                if (letejao.get(i).particular.charAt(0) == '0') {
                    if (letejao.get(i).particular.length() > 3) {
                        int counter = 0;
                        for (int j = 0; j < letejao.get(i).particular.length(); j++) {
                            if (letejao.get(i).particular.charAt(j) == '0') {
                                counter++;
                            } else {
                                break;
                            }
                        }
                        cur = letejao.get(i).steps + counter;
                        if (cur < min) {
                            min = cur;
                        }

                    }

                } else {
                    cur = letejao.get(i).steps;
                    if (cur < min) {
                        min = cur;
                    }
                }

            }
            if (min == Integer.MAX_VALUE) {
                out.println("-1");
            } else {
                out.println(min);
            }
        out.close();

    }

    static class banatejao{

        int steps;
        String particular;

        public banatejao(int steps, String particular) {
            this.steps = steps;
            this.particular = particular;
        }
    }



    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

}