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.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	static final double eps = 1e-9;
	static final long mod = 1000000007; // or 1000000009

	public static void main(String[] args) throws Exception {

		SC scan = new SC();
		// PrintWriter pw = new PrintWriter(System.out);

		String str = scan.nextLine();
		int n = str.length();
		int[] a = new int[n], b = new int[n];
		for (int i = 0; i < n; i++)
			a[n - i - 1] = b[n - i - 1] = str.charAt(i) - '0';
		int ans = Integer.MAX_VALUE;
		int curr = 0;
		boolean gooda = false, goodb = false;
		for (int i = 0; i < n; i++) {
			if (a[i] == 0) {
				gooda = true;
				for (int j = i - 1, k = i; j >= 0; k--, j--, curr++)
					swap(a, k, j);
				break;
			}
		}
		for (int i = 1; i < n; i++) {
			if (a[i] == 0 || a[i] == 5) {
				goodb = true;
				for (int j = i - 1, k = i; j >= 1; k--, j--, curr++)
					swap(a, k, j);
				break;
			}
		}
		for(int i = n-1; a[i] == 0; i--, curr++) {
			if(i <= 1) {
				curr = Integer.MAX_VALUE;
				break;
			}
		}
		if(gooda && goodb) ans = Math.min(ans, curr);
		curr = 0;
		gooda = goodb = false;
		for (int i = 0; i < n; i++) {
			if (b[i] == 5) {
				gooda = true;
				for (int j = i - 1, k = i; j >= 0; k--, j--, curr++)
					swap(b, k, j);
				break;
			}
		}
		for (int i = 1; i < n; i++) {
			if (b[i] == 2 || b[i] == 7) {
				goodb = true;
				for (int j = i - 1, k = i; j >= 1; k--, j--, curr++)
					swap(b, k, j);
				break;
			}
		}
		for(int i = n-1; b[i] == 0; i--, curr++) {
			if(i <= 1) {
				curr = Integer.MAX_VALUE;
				break;
			}
		}
		if(gooda && goodb) ans = Math.min(ans, curr);
		
		if(ans >= Integer.MAX_VALUE) System.out.println(-1);
		else System.out.println(ans);
		// pw.flush();
	}

	static void swap(int[] a, int i, int j) {
		int temp = a[j];
		a[j] = a[i];
		a[i] = temp;
	}
	

	static void sort(int[] arr) {
		for (int i = 1; i < arr.length; i++) {
			int j = (int) ((i + 1) * Math.random());
			int temp = arr[j];
			arr[j] = arr[i];
			arr[i] = temp;
		}
		Arrays.sort(arr);
	}

	static void sort(long[] arr) {
		for (int i = 1; i < arr.length; i++) {
			int j = (int) ((i + 1) * Math.random());
			long temp = arr[j];
			arr[j] = arr[i];
			arr[i] = temp;
		}
		Arrays.sort(arr);
	}

	static class SC {

		BufferedReader br;
		StringTokenizer st;

		public SC() throws Exception {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer("");
		}

		public SC(String fn) throws Exception {
			br = new BufferedReader(new FileReader(fn));
			st = new StringTokenizer("");
		}

		String nextLine() throws Exception {
			return br.readLine();
		}

		String next() throws Exception {
			while (!st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());

		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}

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