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.
maxint = 2147483647

class mylist(list):
    def index(self, obj, *args):
        try:
            if len(args) == 0:
                return super(mylist, self).index(obj)
            if len(args) == 1:
                return super(mylist, self).index(obj,args[0])
            return super(mylist, self).index(obj,args[0],args[1])
        except ValueError:
            return -1
		    
def cost(target,index1, index2):
    if index1 == -1 or index2 == -1:
        return maxint
    if target == '00':
        return index1 + index2 -1
    else:
        return index1 + index2 -1 if index2<index1 else index1+index2

def calcCosts(rn):
    i0 = rn.index('0')
    i00 = rn.index('0',i0+1)
    i2 = rn.index('2')
    i5 = rn.index('5')
    i7 = rn.index('7')
    costs = [('00',cost('00',i0,i00)),('50',cost('50',i5,i0)),('25',cost('25',i2,i5)),('75',cost('75',i7,i5))]
    costs.sort(key=lambda tup:tup[1])
    return costs

def swapCritical(rn,i):
    if i == len(rn)-1:
        for index in range(i-1,-1,-1):
            if rn[index] != '0':
                break
    else:
        index = i-1
    rn[index],rn[index+1] = rn[index+1], rn[index]
    return rn

def swap(rn,typ):
    if typ == '00':
        i0 = rn.index('0')
        i00 = rn.index('0',i0+1)
        if i0 != 0:
            rn[i0-1], rn[i0] = rn[i0], rn[i0-1]
            return rn, 1
        if i00 == 1:
            return rn, 0
        rn[i00-1], rn[i00] = rn[i00], rn[i00-1]
        return rn, 1
    if typ == '50':
        i0 = rn.index('0')
        i5 = rn.index('5')
        if i0 != 0:
            if i0<i5 or i5 == 0:
                rn[i0-1], rn[i0] = rn[i0], rn[i0-1]
                return rn, 1
            rn[i5-1], rn[i5] = rn[i5], rn[i5-1]
            return rn, 1
        if i5 == 1:
            return rn, 0
        if i5 != len(rn)-1:
            rn[i5-1], rn[i5] = rn[i5], rn[i5-1]
            return rn, 1
        rn = swapCritical(rn,i5)
        return rn, 1
    if typ == '25':
        i2 = rn.index('2')
        i5 = rn.index('5')
        if i5 != 0:
            if i5<i2 or i2 == 0:
                swapCritical(rn,i5)
                return rn, 1
            rn[i2-1], rn[i2] = rn[i2], rn[i2-1]
            return rn, 1
        if i2 == 1:
            return rn, 0
        if i2 != len(rn)-1:
            rn[i2-1], rn[i2] = rn[i2], rn[i2-1]
            return rn, 1
        rn = swapCritical(rn,i2)
        return rn, 1
    if typ == '75':
        i7 = rn.index('7')
        i5 = rn.index('5')
        if i5 != 0:
            if i5<i7 or i7 == 0:
                swapCritical(rn,i5)
                return rn, 1
            rn[i7-1], rn[i7] = rn[i7], rn[i7-1]
            return rn, 1
        if i7 == 1:
            return rn, 0
        if i7 != len(rn)-1:
            rn[i7-1], rn[i7] = rn[i7], rn[i7-1]
            return rn, 1
        rn = swapCritical(rn,i7)
        return rn, 1

        
def realCost(rn,maximum):
    costs = calcCosts(rn)
    bestCost = maximum
    for cost in costs:
        if cost[1] >= bestCost:
            return bestCost
        newrn = mylist(rn)
        newrn,tempcost = swap(newrn,cost[0])
        if tempcost == 0:
            return 0
        thiscost = tempcost + realCost(newrn,bestCost-1)
        if thiscost < bestCost:
            bestCost = thiscost
n = input()
rn = n[::-1]
rn = mylist(rn)
rcost = realCost(rn,maxint)
print(rcost if rcost<maxint else -1)
