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.
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	static int n;
	static int f(int a,int b)
	{
		int ret = n-b-1;
		if(b<a)
		{
			a--;
		}
		ret += (n-2)-a;
		return ret;
	}
	
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner("out");
		char[] a = sc.nextLine().toCharArray();
		n = a.length;
		int z1 = -1, z2 = -1 , f5 = -1 , s7 = -1 , t2 = -1;
		for(int i = a.length-1;i>=0;i--)
		{
			if(a[i]=='2' && t2==-1)t2 = i;
			if(a[i]=='7' && s7==-1)s7 = i;
			if(a[i]=='5' && f5==-1)f5 = i;
			if(a[i]=='0' && z1==-1)z1 = i;
			else if(a[i]=='0' && z1!=-1 && z2 == -1)z2=i;
		}
		
		int ans = Integer.MAX_VALUE;
		if(z1!=-1 && z2!=-1)//00
		{
			ans = Math.min(ans, f(z2,z1));
		}
		
		if(t2!=-1 && f5!=-1) // 25
		{
			int tmp = f(t2,f5);
			if(Math.min(t2, f5)==0)
			{
				for (int i = 0; i < a.length; i++) {
					if(i!=t2 && i!=f5 && a[i] != '0')
					{
						tmp += i;
						if(t2<i)
							tmp--;
						if(f5<i)
							tmp--;
						break;
					}
				}
			}
			ans = Math.min(ans, tmp);
		}
		
		
		if(f5!=-1 && z1!=-1) // 50
		{
			int tmp = f(f5,z1);
			if(f5==0 && z1!=1)
			{
				for (int i = 0; i < a.length; i++) {
					if(i!=z1 && i!=f5 && a[i] != '0')
					{
						tmp += i;
						if(z1<i)
							tmp--;
						if(f5<i)
							tmp--;
						break;
					}
				}
			}
			ans = Math.min(ans, tmp);
		}
		
		if(s7!=-1 && f5!=-1) // 75
		{
			int tmp = f(s7,f5);
			if(Math.min(s7, f5)==0)
			{
				for (int i = 0; i < a.length; i++) {
					if(i!=s7 && i!=f5 && a[i] != '0')
					{
						tmp += i;
						if(s7<i)
							tmp--;
						if(f5<i)
							tmp--;
						break;
					}
				}
			}
			ans = Math.min(ans, tmp);
		}
		
		if(ans==Integer.MAX_VALUE)
			System.out.println("-1");
		else
			System.out.println(ans);
		
	}	
	
	
	
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		public Scanner(String s) throws FileNotFoundException {br = new BufferedReader(new FileReader(s));}
		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public String nextLine() throws IOException {return br.readLine();}		
		public long nextLong() throws IOException {return Long.parseLong(next());}		
		public double nextDouble() throws IOException {return Double.parseDouble(next());}	
		public char nextChar() throws IOException{return next().charAt(0);}
		public boolean ready() throws IOException {return br.ready();}
		public int[] nextIntArr() throws IOException{
			st = new StringTokenizer(br.readLine());
			int[] res = new int[st.countTokens()];
			for (int i = 0; i < res.length; i++)
				res[i] = nextInt();
			return res;
		}
		public char[] nextCharArr() throws IOException{
			st = new StringTokenizer(br.readLine());
			char[] res = new char[st.countTokens()];
			for (int i = 0; i < res.length; i++) 
				res[i] = nextChar();
			return res;
		}
	}

}