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.util.Scanner;
import java.util.Arrays;

public class DivBy25 {
	public static void main(String[] args) {
		Scanner console = new Scanner(System.in);
		String numAsStr = console.next();
		//Array representing distance from end i.e. number of swaps needed to get to the end
		int[] numSwaps = new int[numAsStr.length()];
		for (int i = numSwaps.length-1; i>=0; i--)
			numSwaps[i] = numAsStr.length()-i-1;
		//Look for 0s
		boolean[] is0 = new boolean[numAsStr.length()];
		boolean[] is2 = new boolean[numAsStr.length()];
		boolean[] is5 = new boolean[numAsStr.length()];
		boolean[] is7 = new boolean[numAsStr.length()];
		if (numAsStr.contains("0")&&numAsStr.contains("5")
			||numAsStr.contains("7")&&numAsStr.contains("5")
			||numAsStr.contains("2")&&numAsStr.contains("5")
			||numAsStr.contains("0")&&(numAsStr.substring(0, numAsStr.indexOf("0"))+numAsStr.substring(numAsStr.indexOf("0")+1)).contains("0"))
		{
		for (int i = 0; i<numAsStr.length(); i++)
			if (numAsStr.charAt(i) == '0')
				is0[i] = true;
			else if (numAsStr.charAt(i) == '2')
				is2[i] = true;
			else if (numAsStr.charAt(i) == '5')
				is5[i] = true;
			else if (numAsStr.charAt(i) == '7')
				is7[i] = true;
		
		int result = Integer.MAX_VALUE;

		int pickedD1 = Integer.MAX_VALUE;
		int pickedD2 = Integer.MAX_VALUE;

		//For numbers ending with 00
		for (int i = 0; i<is0.length-1; i++) {
			for (int j = i+1; j<is0.length; j++) {
				if (is0[i] && is0[j]) {
					if (numSwaps[i]+numSwaps[j]-1+get0Penalty(numAsStr, i, j)<result) {
						pickedD1 = Integer.parseInt(numAsStr.charAt(i)+"");
						pickedD2 = Integer.parseInt(numAsStr.charAt(j)+"");
						String clonedStr = numAsStr;
					 	result = numSwaps[i]+numSwaps[j]-1+get0Penalty(clonedStr, i, j); 
					}
				}
				else if (is0[j] && is0[i])
					if (numSwaps[i]+numSwaps[j]+get0Penalty(numAsStr, i, j)<result) {
						pickedD1 = Integer.parseInt(numAsStr.charAt(i)+"");
						pickedD2 = Integer.parseInt(numAsStr.charAt(j)+"");
						String clonedStr = numAsStr;
					 	result = numSwaps[i]+numSwaps[j]+get0Penalty(clonedStr, i, j); 
					}
			}
		}

		//For numbers ending with 50
		for (int i = 0; i<is0.length-1; i++) {
			for (int j = i+1; j<is0.length; j++) {
				if (is5[i] && is0[j]) {
					if (numSwaps[i]+numSwaps[j]-1+get0Penalty(numAsStr, i, j)<result) 
					{
						pickedD1 = Integer.parseInt(numAsStr.charAt(i)+"");
						pickedD2 = Integer.parseInt(numAsStr.charAt(j)+"");
						String clonedStr = numAsStr;
						result = numSwaps[i]+numSwaps[j]-1+get0Penalty(clonedStr, i, j);
					}
				}
				else if (is5[j] && is0[i])
					if (numSwaps[i]+numSwaps[j]+get0Penalty(numAsStr, i, j)<result) {
						pickedD1 = Integer.parseInt(numAsStr.charAt(i)+"");
						pickedD2 = Integer.parseInt(numAsStr.charAt(j)+"");
						String clonedStr = numAsStr;
					 	result = numSwaps[i]+numSwaps[j]+get0Penalty(clonedStr, i, j); 
					}
			}
		}

		//For numbers ending with 25
		for (int i = 0; i<is0.length-1; i++) {
			for (int j = i+1; j<is0.length; j++) {
				if (is2[i] && is5[j]) {
					if (numSwaps[i]+numSwaps[j]-1+get0Penalty(numAsStr, i, j)<result) 
					{
						pickedD1 = Integer.parseInt(numAsStr.charAt(i)+"");
						pickedD2 = Integer.parseInt(numAsStr.charAt(j)+"");
						String clonedStr = numAsStr;
						result = numSwaps[i]+numSwaps[j]-1+get0Penalty(clonedStr, i, j);
					}
				}
				else if (is2[j] && is5[i])  {
					if (numSwaps[i]+numSwaps[j]+get0Penalty(numAsStr, i, j)<result) {
						pickedD1 = Integer.parseInt(numAsStr.charAt(i)+"");
						pickedD2 = Integer.parseInt(numAsStr.charAt(j)+"");
						String clonedStr = numAsStr;
					 	result = numSwaps[i]+numSwaps[j]+get0Penalty(clonedStr, i, j); 
					}	
				}
			}
		}

		//For numbers ending with 75
		for (int i = 0; i<is0.length-1; i++) {
			for (int j = i+1; j<is0.length; j++) {
				if (is7[i] && is5[j]) {
					if (numSwaps[i]
						+numSwaps[j]
						-1+get0Penalty(numAsStr, i, j)<result) 
					{
						pickedD1 = Integer.parseInt(numAsStr.charAt(i)+"");
						pickedD2 = Integer.parseInt(numAsStr.charAt(j)+"");
						String clonedStr = numAsStr;
						result = numSwaps[i]+numSwaps[j]-1+get0Penalty(clonedStr, i, j);
					}
				}
				else if (is7[j] && is5[i])
					if (numSwaps[i]+numSwaps[j]+get0Penalty(numAsStr, i, j)<result) {
						pickedD1 = Integer.parseInt(numAsStr.charAt(i)+"");
						pickedD2 = Integer.parseInt(numAsStr.charAt(j)+"");
						String clonedStr = numAsStr;
					 	result = numSwaps[i]+numSwaps[j]+get0Penalty(clonedStr, i, j); 
					}
			}
		}
		System.out.println(result);
		}
		else if (numAsStr.equals("0"))
			System.out.println(0);
		else
			System.out.println(-1);
	}

	public static int get0Penalty(String number, int index1, int index2) {
		String zerosTBR = "";
		String end = "";
		if (index2 != number.length()-1) {
			end = number.substring(index1+1, index2)+number.substring(index2+1);
			zerosTBR = number.substring(0, index1)+end;
		}
		else
			zerosTBR = number.substring(0, index1)+number.substring(index1+1, index2);
		int counter = 0;
		if (!zerosTBR.equals("")) {
			while (!zerosTBR.equals("") && zerosTBR.charAt(0) == '0') {
				counter++;
				zerosTBR = zerosTBR.substring(1);
			}
		}
		return counter;
	}
}