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:


def check():
   res = 0
   if (cnt[0]>1):
      res += 1
   if (cnt[0]>0 and cnt[5]>0):
      res += 2
   if (cnt[5]>0 and (cnt[2]>0 or cnt[7]>0)):
      res += 4
   return res


num = int(input())

cnt = []
str = []

for i in range(10):
   cnt.append(0)
#print("cnt's length is ",len(cnt))
while num != 0:
   i = num%10
#   print("num =",num," i = ",i)
   str.append(i)
   cnt[i]+=1
   num //= 10
k = check()
ans = 40
if (k==0):
   print("-1")
if (k&1==1):#00
   tmp = index = 0
   cok = 2
   for i in str :
      if i==0 :
         tmp += index
         cok -= 1
      index += 1
      if cok == 0:
         break
   ans = min(ans,tmp-1)
if  k&2==2:#50
   
   index = 0
   zero = five = -1
   for i in str :
      if i==0 and zero == -1 :
         zero = index
      elif i==5 and five == -1 :
         five = index
      index += 1
   if zero < five :
      ans = min(ans,zero+five-1)
   else :
      ans = min(ans,zero+five)
if k&4==4:#25 or 75
   index = 0
   five = tos = -1
   for i in str :
      if i==5 and five == -1:
         five = index
      elif tos == -1 and ( i==2 or i==7 ):
         tos = index
      index += 1
   if five < tos :
      ans = min(ans,five+tos-1)
   else :
      if five == len(str)-1:
         index = five-1
         while index >=0 and ( index == tos or str[index]==0 ):
            index -= 1;
         else :
            if index == five-1:
               ans = min(ans,five+tos)
            elif index != -1:
               tmp = five-index
               five -= 1
               if index < tos:
                  tos -= 1
               tmp += five + tos
               ans = min(ans,tmp)
            else :
               if len(str)==2:
                  ans = 1
               
      else :
         ans = min(ans,five+tos)
if k!=0 :
   print(ans)