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 PYTHON3):

Solution:
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq

#sys.setrecursionlimit(10**6) 
#OneDrive\Documents\codeforces

I=sys.stdin.readline

alpha="abcdefghijklmnopqrstuvwxyz"

"""
x_move=[-1,0,1,0,-1,1,1,-1]
y_move=[0,1,0,-1,1,1,-1,-1]
"""
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())


def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom 
 

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def isPrime(n):
	if n<=1:
		return False
	elif n<=2:
		return True
	else:
		
		for i in range(2,int(n**.5)+1):
			if n%i==0:
				return False
		return True


#print("Case #"+str(_+1)+":",abs(cnt-k))



def f(s,a,b,c):
	arr=list(s)
	cost1=c
	l=len(arr)-1
	f=0
	for need in [b,a]:		
		for i in range(l,-1,-1):
			if arr[i]==need:
			
				f+=1
				x=i 
				while x!=l:
					cost1+=1
					arr[x],arr[x+1]=arr[x+1],arr[x]
					x+=1
				break

		l-=1
	# print(cost1,arr)
	# arr=list(s)
	# cost2=c
	# l=len(arr)-1
	# f1=0
	# for need in [a,b]:
		
	# 	for i in range(l,-1,-1):
	# 		if arr[i]==need:
	# 			# print(arr[i],need)
	# 			f1+=1
	# 			x=i 
	# 			while x!=l:
	# 				# print(x,l,need,arr)
	# 				cost2+=1
	# 				arr[x],arr[x+1]=arr[x+1],arr[x]
	# 				x+=1
	# 			break

	# 	l-=1
	# print(cost2,arr)
	# print()

	if f!=2 or arr[0]=="0":
		cost1=math.inf 
	
	return cost1




def main():
	
	n=ii()
	ans=math.inf
	s=str(n)


	# print(f("25067","7","5",2))
	i=0

	while i<len(s):
		if s[i]!="0":
			tmp=list(s)
			x=i
			c=0
			while x!=0:
				tmp[x],tmp[x-1]=tmp[x-1],tmp[x]
				x-=1
				c+=1

			tmp="".join(tmp)
			# print(tmp,c)

			ans=min(ans,f(tmp,"0","0",c),f(tmp,"2","5",c),f(tmp,"5","0",c),f(tmp,"7","5",c))

		i+=1

	if ans==math.inf:
		print(-1)
	else:
		print(ans)














	








	




		
	

					

if __name__ == '__main__':
	main()