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.*;
import java.math.*;
import java.util.*;

public class E_divisibilityBy25 {
    public static void main(String[] args) throws IOException {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        
        String str = sc.next();
        if (str.length() == 1) {
        	if (str.contentEquals("0")) {
        		pw.println(0);
        	}
        	else pw.println(-1);
        }
        else if (str.length() == 2) {
        	if (str.contentEquals("25") || str.contentEquals("50") || str.contentEquals("75")) {
        		pw.println(0);
        	}
        	else if (str.contentEquals("52") || str.contentEquals("57")) {
        		pw.println(1);
        	}
        	else pw.println(-1);
        }
        else {
        // 00
        int zero1 = -1;
        int zero2 = -1;
        int min = 2*str.length();
        for (int i = str.length()-1; i >= 0; i--) {
        	if (Integer.parseInt(str.substring(i,i+1)) == 0) {
        		zero1 = i;
        		for (int j = i-1; j >= 0; j--) {
        			if (Integer.parseInt(str.substring(j,j+1)) == 0) {
        				zero2 = j;
        				break;
        			}
        		}
        		break;
        	}
        }
        if (zero2 != -1 && !(zero2 == 0 && zero1 == 1)) {
        	min = Math.min(min, 2*str.length()-3-zero1-zero2);
        }
        // 25
        int two = -1;
        int five = -1;
        for (int i = str.length()-1; i >= 0; i--) {
        	if (two == -1 && Integer.parseInt(str.substring(i,i+1)) == 2) {
        		two = i;
        	}
        	if (five == -1 && Integer.parseInt(str.substring(i,i+1)) == 5) {
        		five = i;
        	}
        }
        if (two != -1 && five != -1) {
        	if (two < five) {
        		if (!(two == 0 && Integer.parseInt(str.substring(1,2)) == 0)) {
        			min = Math.min(min, 2*str.length()-3-two-five);
        		}
        		else {
        			//pw.println("WTMOO");
        			// find the first element that is not 0, and also not equal to the position of five
        			// swap element with position at index 1
        			// if element < five
        			// if element > five ans minus 1 more
        			int pos = -1;
        			for (int i = 1; i < str.length(); i++) {
        				if (Integer.parseInt(str.substring(i,i+1)) != 0) {
        					if (i != five) {
        						pos = i;
        						break;
        					}
        				}
        			}
        			if (pos != -1) {
        				if (pos < five) {
        					min = Math.min(min, pos-1+str.length()-1-five+str.length()-2);
        				}
        				else min = Math.min(min, pos-1+str.length()-1-five+str.length()-2-1);
         			}
        		}
        	}
        	else {
        		if (!(five == 0 && Integer.parseInt(str.substring(1,2)) == 0)) {
        			min = Math.min(min, 2*str.length()-2-two-five);
        		}
        		else {
        			//pw.println("WTMOO2");
        			int pos = -1;
        			for (int i = 1; i < str.length(); i++) {
        				if (Integer.parseInt(str.substring(i,i+1)) != 0) {
        					if (i != two) {
        						pos = i;
        						//pw.println("pos = " + pos);
        						break;
        					}
        				}
        			}
        			if (pos != -1) {
        				if (pos < two) {
        					min = Math.min(min, pos-1+str.length()-1-two+str.length()-2+1);
        				}
        				else {
        					//pw.println(pos-1+str.length()-1-two+str.length()-2-1);
        					min = Math.min(min, pos-1+str.length()-1-two+str.length()-2-1+1);
        				}
        			}
        		}
        	}
        }
        // 50
        int zero = -1;
        five = -1;
        for (int i = str.length()-1; i >= 0; i--) {
        	if (zero == -1 && Integer.parseInt(str.substring(i,i+1)) == 0) {
        		zero = i;
        	}
        	if (five == -1 && Integer.parseInt(str.substring(i,i+1)) == 5) {
        		five = i;
        	}
        }
        if (zero != -1 && five != -1) {
        	if (zero < five) {
        		if (!(zero == 0 && Integer.parseInt(str.substring(1,2)) == 0)) {
        			min = Math.min(min, 2*str.length()-2-zero-five);
        		}
        	}
        	else {
        		if (!(five == 0 && Integer.parseInt(str.substring(1,2)) == 0)) {
        			min = Math.min(min, 2*str.length()-3-zero-five);
        		}
        		else {
        			int notZero = -1;
        			for (int i = 1; i < str.length(); i++) {
        				if (Integer.parseInt(str.substring(i,i+1)) != 0) {
        					notZero = i;
        					break;
        				}
        			}
        			if (notZero != -1) {
        				if (notZero < zero) {
        					min = Math.min(min, notZero-1+str.length()-1-zero+str.length()-2);
        				}
        				else min = Math.min(min, notZero-1+str.length()-1-zero+str.length()-2-1);
        			}
        		}
        	}
        }
        // 75
        int seven = -1;
        five = -1;
        for (int i = str.length()-1; i >= 0; i--) {
        	if (seven == -1 && Integer.parseInt(str.substring(i,i+1)) == 7) {
        		seven = i;
        	}
        	if (five == -1 && Integer.parseInt(str.substring(i,i+1)) == 5) {
        		five = i;
        	}
        }
        if (seven != -1 && five != -1) {
        	if (seven < five) {
        		if (!(seven == 0 && Integer.parseInt(str.substring(1,2)) == 0)) {
        			min = Math.min(min, 2*str.length()-3-seven-five);
        		}
        		else {
        			//pw.println("WTMOO3");
        			int pos = -1;
        			for (int i = 1; i < str.length(); i++) {
        				if (Integer.parseInt(str.substring(i,i+1)) != 0) {
        					if (i != five) {
        						pos = i;
        						break;
        					}
        				}
        			}
        			if (pos != -1) {
        				if (pos < five) {
        					min = Math.min(min, pos-1+str.length()-1-five+str.length()-2);
        				}
        				else min = Math.min(min, pos-1+str.length()-1-five+str.length()-2-1);
        			}
        		}
        	}
        	else {
        		if (!(five == 0 && Integer.parseInt(str.substring(1,2)) == 0)) {
        			min = Math.min(min, 2*str.length()-2-seven-five);
        		}
        		else {
        			//pw.println("WTMOO4");
        			int pos = -1;
        			for (int i = 1; i < str.length(); i++) {
        				if (Integer.parseInt(str.substring(i,i+1)) != 0) {
        					if (i != seven) {
        						pos = i;
        						//pw.println("pos = " + pos);
        						break;
        					}
        				}
        			}
        			if (pos != -1) {
        				if (pos < seven) {
        					min = Math.min(min, pos-1+str.length()-1-seven+str.length()-2+1);
        				}
        				else min = Math.min(min, pos-1+str.length()-1-seven+str.length()-2-1+1);
        			}
        		}
        	}
        }
        if (min == 2*str.length()) {
        	min = -1;
        }
        pw.println(min);
        }
        
        pw.close();
    }
    static class FastScanner {
    	private boolean finished = false;

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

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

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

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

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }
        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }
        public String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines) {
                return readLine();
            } else {
                return readLine0();
            }
        }

        public BigInteger readBigInteger() {
            try {
                return new BigInteger(nextString());
            } catch (NumberFormatException e) {
                throw new InputMismatchException();
            }
        }

        public char nextCharacter() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            return (char) c;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean isExhausted() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value == -1;
        }
    public String next() {
            return nextString();
        }

        public SpaceCharFilter getFilter() {
            return filter;
        }

        public void setFilter(SpaceCharFilter filter) {
            this.filter = filter;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
        public int[] nextIntArray(int n){
            int[] array=new int[n];
            for(int i=0;i<n;++i)array[i]=nextInt();
            return array;
        }
        public int[] nextSortedIntArray(int n){
            int array[]=nextIntArray(n);
            PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
            for(int i = 0; i < n; i++){
                pq.add(array[i]);
            }
            int[] out = new int[n];
            for(int i = 0; i < n; i++){
                out[i] = pq.poll();
            }
            return out;
        }
        public int[] nextSumIntArray(int n){
            int[] array=new int[n];
            array[0]=nextInt();
            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
            return array;
        }
        public ArrayList<Integer>[] nextGraph(int n, int m){
            ArrayList<Integer>[] adj = new ArrayList[n];
            for(int i = 0; i < n; i++){
                adj[i] = new ArrayList<Integer>();
            }
            for(int i = 0; i < m; i++){
                int u = nextInt(); int v = nextInt();
                u--; v--;
                adj[u].add(v); adj[v].add(u);
            }
            return adj;
        }
        public ArrayList<Integer>[] nextTree(int n){
            return nextGraph(n, n-1);
        }

        public long[] nextLongArray(int n){
            long[] array=new long[n];
            for(int i=0;i<n;++i)array[i]=nextLong();
            return array;
        }
        public long[] nextSumLongArray(int n){
            long[] array=new long[n];
            array[0]=nextInt();
            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
            return array;
        }
        public long[] nextSortedLongArray(int n){
            long array[]=nextLongArray(n);
            Arrays.sort(array);
            return array;
        }
    }
	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;
		}
	}
}