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 bisect
import math
import sys
from collections import deque

#input = sys.stdin.readline


def main():
    s = list(input())

    def check(last_but_one, last):
        t = s.copy()
        n = len(t)
        res = 0

        pos_last = n-1
        while pos_last >= 0 and t[pos_last] != last:
            pos_last -= 1
        if pos_last < 0:
            return False
        while pos_last < n-1:
            t[pos_last], t[pos_last+1] = t[pos_last+1], t[pos_last]
            res += 1
            pos_last += 1

        pos_last_but_one = n-2
        while pos_last_but_one >= 0 and t[pos_last_but_one] != last_but_one:
            pos_last_but_one -= 1
        if pos_last_but_one < 0:
            return False
        while pos_last_but_one < n-2:
            t[pos_last_but_one], t[pos_last_but_one+1] = t[pos_last_but_one+1], t[pos_last_but_one]
            res += 1
            pos_last_but_one += 1

        if t[-1] != last or t[-2] != last_but_one:
            return False

        pos = 0
        while pos < n and t[pos] == '0':
            pos += 1
        if pos == n:
            return False

        while pos > 0:
            t[pos-1], t[pos] = t[pos], t[pos-1]
            pos -= 1
            res += 1

        if t[-1] != last or t[-2] != last_but_one:
            return False

        return res

    if len(s) == 1:
        print(-1)
    else:
        ans = math.inf
        for a, b in (('0', '0'), ('2', '5'), ('5', '0'), ('7', '5')):
            if a == s[-2] and b == s[-1]:
                ans = 0
                break
            ver = check(a, b)
            if ver:
                ans = min(ans, ver)
        print(-1 if ans == math.inf else ans)


if __name__ == '__main__':
    main()