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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.StringTokenizer;


public class WCS {
	public static boolean DEBUG = false;
	public static int solve(long n) {
		if(n < 100) {
			if(n == 25 || n == 50 || n == 75) 
				return 0;
			if(n == 52 || n == 57)
				return 1;
			return -1;
		}
		int ans = Integer.MAX_VALUE;
		char[] s = String.valueOf(n).toCharArray();
		if(s[s.length - 1] != '0') {
			for(int j = s.length - 2; j >= 0; j --) {
				if(s[j] == '0') {
					char[] s1 = s.clone();
					char c = s[j];
					for(int x = j; x < s.length - 1; x ++)
						s1[x] = s1[x + 1];
					s1[s.length - 1] = c;
					for(int x = s.length - 2; x >= 0; x --) {
						if(s1[x] == '5' || s1[x] == '0') {
							c = s1[x];
							for(int z = x; z < s.length - 2; z ++)
								s1[z] = s1[z + 1];
							s1[s.length - 2] = c;
							if(s1[0] != '0')
								ans = Math.min(ans, s.length - 1 - j + s.length - 2 - x);
							else {
								int q = 1;
								for(; s1[q] == '0'; q ++);
								ans = Math.min(ans, s.length - 1 - j + s.length - 2 - x + q);
								if(DEBUG)
									System.out.println("0 -> " + String.valueOf(s1) + " " + (s.length - 1 - j + s.length - 2 - x + q));
							}
							if(DEBUG)
								System.out.println(String.valueOf(s1));
						}
					}
				}
			}
		}
		if(s[s.length - 1] == '0') {
			char[] s1 = s.clone();
			for(int x = s.length - 2; x >= 0; x --) {
				if(s1[x] == '5' || s1[x] == '0') {
					char c = s1[x];
					for(int z = x; z < s.length - 2; z ++)
						s1[z] = s1[z + 1];
					s1[s.length - 2] = c;
					if(s1[0] != '0')
						ans = Math.min(ans, s.length - 2 - x);
					else {
						int q = 1;
						for(; s1[q] == '0'; q ++);
						ans = Math.min(ans, s.length - 2 - x + q);
						if(DEBUG)
							System.out.println("0 -> " + String.valueOf(s1) + " " + (s.length - 2 - x + q));
					}
					if(DEBUG)
						System.out.println(String.valueOf(s1));
				}
			}
		}
		if(s[s.length - 1] != '5') {
			for(int j = s.length - 2; j >= 0; j --) {
				if(s[j] == '5') {
					char[] s1 = s.clone();
					char c = s[j];
					for(int x = j; x < s.length - 1; x ++)
						s1[x] = s1[x + 1];
					s1[s.length - 1] = c;
					for(int x = s.length - 2; x >= 0; x --) {
						if(s1[x] == '2' || s1[x] == '7') {
							c = s1[x];
							for(int z = x; z < s.length - 2; z ++)
								s1[z] = s1[z + 1];
							s1[s.length - 2] = c;
							if(s1[0] != '0')
								ans = Math.min(ans, s.length - 1 - j + s.length - 2 - x);
							else {
								int q = 1;
								for(; s1[q] == '0'; q ++);
								ans = Math.min(ans, s.length - 1 - j + s.length - 2 - x + q);
								if(DEBUG)
									System.out.println("0 -> " + String.valueOf(s1) + " " + (s.length - 1 - j + s.length - 2 - x + q));
							}
							if(DEBUG)
								System.out.println(String.valueOf(s1));
						}
					}
				}
			}
		}
		if(s[s.length - 1] == '5') {
			char[] s1 = s.clone();
			for(int x = s.length - 2; x >= 0; x --) {
				if(s1[x] == '2' || s1[x] == '7') {
					char c = s1[x];
					for(int z = x; z < s.length - 2; z ++)
						s1[z] = s1[z + 1];
					s1[s.length - 2] = c;
					if(s1[0] != '0')
						ans = Math.min(ans, s.length - 2 - x);
					else {
						int q = 1;
						for(; s1[q] == '0'; q ++);
						ans = Math.min(ans, s.length - 2 - x + q);
						if(DEBUG)
							System.out.println("0 -> " + String.valueOf(s1) + " " + (s.length - 2 - x + q));
					}
					if(DEBUG)
						System.out.println(String.valueOf(s1));
				}
			}
		}
		return ans == Integer.MAX_VALUE ? -1 : ans;
	}
	
	public static void main(String... args) {
		System.out.println(solve(in.nextLong()));
	}
	
	static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                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());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
	
    static FastReader in = new FastReader();
}