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 inx(a,s):
    ll = []
    for i in range(len(a)):
        if s == a[i]:
            ll.append(i)
    try:
        return max(ll)
    except:
        return False

def check(a, Comb):
    Counter = 0
    Nxt = inx(a,Comb[1])
    if Nxt is False:
        Counter = 0
    else:
        for i in range(Nxt+1, len(a)):
            a[i-1], a[i] = a[i], a[i-1]
            Counter+=1
            
    Fst = inx(a,Comb[0])
    if Fst is False:
        Counter = 0
    else:
        for i in range(Fst+1, len(a)-1):
            a[i-1], a[i] = a[i], a[i-1]
            Counter+=1
    if Fst is False:
        Counter = None
    if Nxt is False:
        Counter = None
    return Counter
    
def search(a):
    s = None
    flg = False
    for i in range(len(a)):
        if flg is True:
            break
        if a[i] == '2':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '255'
                    flg = True
                    break
        elif a[i] == '5':
            for j in range(len(a)):
                if a[j] == '2':
                    s = '255'
                    flg = True
                    break
                elif a[j] == '7':
                    s = '755'
                    flg = True
                    break
                elif a[j] == '0':
                    s = '505'
                    flg = True
                    break
        elif a[i] == '7':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '755'
                    flg = True
                    break
        elif a[i] == '0':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '500'
                    flg = True
                    break
                elif a[j] == '0' and i != j:
                    s = '000'
                    flg = True
                    break
    if s is None:
        print(-1)
        exit()
    return s
 
#def swap(a,b):
#    a, b = b, a
#    return b, a

def czero(a):
        ctr = 0
        index = None
        for i in range(len(a)):
            if a[i] != '0':
                index = i
                break
        if index == 0:
            return None
        else:
            cou = index
            while a[0] == '0':
                a[cou-1], a[cou] = a[cou], a[cou-1]
                ctr+=1
                cou-=1
            return ctr

def search1(a, t, Comb):
        s = None
        flg = False

        if Comb[2] == '5':
                if '2' not in t:
                    s = '255'
                    t.append('2')

                elif  '7' not in t:
                    s = '755'
                    t.append('7')
                elif '0' not in t:
                    s = '505'
                    t.append('0')
        elif Comb[2] == '0':
                if '5' not in t:
                    s = '500'
                    t.append('5')
                elif '0' not in t:
                    s = '000'
                    t.append('0')
                else:
                    s = '---'
        return s, t
def ZERO(a, mass):
    Counter = 0
    #print(a)
    Nxt = None
    Fst = None
    for i in range(len(a)):
        
        if a[i] == '0':
            if not Fst:
                Fst = i
            elif not Nxt:
                Nxt = i
            else:
                break
    
    if Fst is None:
        return mass, None
    elif Nxt is None:
        return mass, None
    else:
        for i in range(Nxt+1, len(a)):
            a[i-1], a[i] = a[i], a[i-1]
            Counter+=1
            
        for i in range(Fst+1, len(a)-1):
            a[i-1], a[i] = a[i], a[i-1]
            Counter+=1
            
        f = czero(a)
        if f is not None:
             Counter+=f
             
        mass.append(Counter)
        return mass, Counter
    
mass = []
temp = []
Counter = 0
a=input()[::-1]
if a[0] == '5' and a[1] == '2':
    print(0)
    exit()
if a[0] == '5' and a[1] == '7':
    print(0)
    exit()
if a[0] == '0' and a[1] == '0':
    print(0)
    exit()
if a[0] == '0' and a[1] == '5':
    print(0)
    exit()
    
Comb = search(a)

if Comb == '000':
    a = list(a)[::-1]
    Nxt = None
    Fst = None
    i = len(a)-1
    while i != 0:
        
        if a[i] == '0':
            if not Fst:
                Fst = i
            elif not Nxt:
                Nxt = i
            else:
                break
        i-=1
    #print(Fst,Nxt)
    
    for i in range(Fst+1, len(a)):
        a[i-1], a[i] = a[i], a[i-1]
        Counter+=1
        
    for i in range(Nxt+1, len(a)-1):
        a[i-1], a[i] = a[i], a[i-1]
        Counter+=1
        
    f = czero(a)
    if f is not None:
         Counter+=f
         
    mass.append(Counter)
    
else:
    b = a
    for i in range(3):
        a = list(b)[::-1]
        #print(a)
        Counter = 0
        Comb2, temp = search1(a, temp, Comb)
        if Comb2 == '---':
            pass
        elif Comb2 == '000':
            mass, Counter = ZERO(a, mass)
            if Counter is not None:
                f = czero(a)
                if f is not None:
                    Counter+=f
                    
                mass.append(Counter)
        else:
            Counter=check(a, Comb2)
            if Counter is not None:
                f = czero(a)
                if f is not None:
                    Counter+=f
                    
                mass.append(Counter)
print(min(mass))

#50267 |