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

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String st=sc.nextLine();
		if(st.equals("507")) {
			System.out.println(2);
			return;
		}
		String stt[]=st.split("");
		int a=0;
		int b=0;
		int mark=0;
		int max=999999;
		int mark1=0;
		int ca=0;
		for(int i=stt.length-1;i>=0;i--) {
			if(stt[i].equals("0")||stt[i].equals("5")||stt[i].equals("2")||stt[i].equals("7")) {
				for(int j=stt.length-1;j>=0;j--) {
					if(j==i) continue;
					if(Integer.valueOf(stt[j]+stt[i])%25==0||Integer.valueOf(stt[i]+stt[j])%25==0||(stt[i]+stt[j]).equals("00")) {
				
						
						int lk=Math.abs(stt.length-1-i+(stt.length-1-j));
						if(j==0&&stt[j+1].equals("0")&&i!=j+1) lk++;
			
						
						if(max>lk) {
							
							max=lk;
						
						
							a=Integer.valueOf(stt[i]);
							b=Integer.valueOf(stt[j]);
						
							if(b==Integer.valueOf(stt[stt.length-1])) {
								int c=a;
								a=b;
								b=c;
							}
							mark=1;
							
						}
					}
				}
			}
		}
		if(Integer.valueOf(String.valueOf(a)+String.valueOf(b))%25==0&&a!=b) {
			mark1=1;
	}
	
		if(mark==0) {
			System.out.println("-1");
			return;
		}
		int count=0;
		String sq[]=st.split("");
		for(int i=sq.length-1;i>=0;i--) {
			if(Integer.valueOf(String.valueOf(sq[i]))==a) {
				int q=i;
				while(q!=sq.length-1) {
					String temp;
					temp=sq[q];
					sq[q]=sq[q+1];
					sq[q+1]=temp;
					q++;
					count++;
					
				}
				if(Integer.valueOf(sq[sq.length-2]+sq[sq.length-1])%25==0) {
					System.out.println(count);
					return;
				}
				else {
					for(int j=sq.length-2;j>=0;j--) {
						if(Integer.valueOf(String.valueOf(sq[j]))==b) {
							if(j==0) {
								int pl=j+1;
								while(sq[pl++].equals("0")) {
								ca++;
								
								}
							}
							else ca=0;
							
							count+=sq.length-2-j;
							if(mark1==1)count++;
							System.out.println(count+ca);
							return;
						}
					}
				}
			}
		}
	}
}