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.
// package CodeForces;

import java.io.*;
import java.util.*;

public class Problem_988E {
	static boolean valid(char[]tmp)
	{
//		System.out.println(Arrays.toString(tmp));
		int n=tmp.length;
		if(tmp[n-2]=='2' && tmp[n-1]=='5')
			return true;
		if(tmp[n-2]=='5' && tmp[n-1]=='0')
			return true;
		if(tmp[n-2]=='7' && tmp[n-1]=='5')
			return true;
		if(tmp[n-2]=='0' && tmp[n-1]=='0')
			return true;
		return false;
	}
	static int move(int i,int j)
	{
		char []tmp=c.clone();
		int moves=0;
//		System.out.println(i+" "+j);
		if(i>j)
			i--;
		while(j<tmp.length-1)
		{
			char cc=tmp[j];
			tmp[j]=tmp[j+1];
			tmp[j+1]=cc;
			moves++;
			j++;
		}
		while(i<tmp.length-2)
		{
			char cc=tmp[i];
			tmp[i]=tmp[i+1];
			tmp[i+1]=cc;
			moves++;
			i++;
		}
		int z;
		for(z=0;z<tmp.length;z++)
			if(tmp[z]!='0')
			{
				char cc=tmp[z];
				tmp[z]=tmp[0];
				tmp[0]=cc;
				moves+=z;
				break;
			}
//		System.out.println(Arrays.toString(tmp));
		if(valid(tmp))
			return moves;
		return -1;
	}
	static int solve(int x,int y)
	{
		int ans=(int)1e9;
		for(int i:lastindx[x])
		{
			for(int j:lastindx[y])
			{
				if(i==j)
					continue;
				int move=move(i,j);
//				System.out.println(Arrays.toString(c));
				if(move!=-1)
					ans=Math.min(ans, move);
			}
		}
		return ans;
	}
//	static int zero;
	static char c[];
	static ArrayList<Integer> lastindx[];
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		c=sc.nextLine().toCharArray();
		int[]a=new int[10];
		lastindx=new ArrayList[10];
		for(int i=0;i<10;i++)
			lastindx[i]=new ArrayList<>();
//		System.out.println(Arrays.toString(c));
		for(int i=0;i<c.length;i++)
		{
			a[c[i]-'0']++;
//			if(c[i]=='0')
//				zero=lastindx[0];
			lastindx[c[i]-'0'].add(i);
		}
		//check for 25 or 50 or 75 or 00
		int ans=(int)1e9;
//		if(a[2]>0 && a[5]>0)
			ans=Math.min(ans, solve(2,5));
//		if(a[5]>0 && a[0]>0)
			ans=Math.min(ans, solve(5,0));
//		if(a[7]>0 && a[5]>0)
			ans=Math.min(ans, solve(7,5));
//		if(a[0]>1)
			ans=Math.min(ans, solve(0,0));
		pw.print(ans==(long)1e9?-1:ans);
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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

		boolean hasnext() throws IOException {
			return br.ready();
		}

	}
}
