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
input = sys.stdin.readline

n = list(input().rstrip())
m = len(n)
inf = 114514
if m == 1:
    ans = -1
elif m == 2:
    x = 10 * int(n[0]) + int(n[1])
    if x % 25 == 0:
        ans = 0
    elif x == 52 or x == 57:
        ans = 1
    else:
        ans = -1
else:
    ans = inf
    for i in range(m):
        if int(n[i]) % 5:
            continue
        n0 = list(n)
        cnt = 0
        f = 1
        if i == 0:
            f = 0
            for j in range(1, m - 1):
                if not int(n0[j]) == 0:
                    f = 1
                    cnt += j - 1
                    for k in range(j - 1, 0, -1):
                        n0[k], n0[k + 1] = n0[k + 1], n0[k]
                    break
        if not f:
            continue
        for j in range(m - i - 1):
            n0[i + j], n0[i + j + 1] = n0[i + j + 1], n0[i + j]
            cnt += 1
        if int(n0[0]) == 0:
            continue
        if not 10 * int(n0[-2]) + int(n0[-1]) % 25:
            ans = min(ans, cnt)
            continue
        c = min(2, int(n0[-1]))
        f = 0
        for j in range(m - 2, 0, -1):
            if int(n0[j]) % 5 == c:
                f = 1
                cnt += m - 2 - j
                ans = min(ans, cnt)
                break
        if not f and int(n0[0]) % 5 == c:
            cnt += m - 2
            f = 0
            for j in range(1, m - 1):
                if int(n0[j]):
                    f = 1
                    cnt += j - 1
                    break
            if f:
                ans = min(ans, cnt)
if not ans ^ inf:
    ans = -1
print(ans)