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 JAVA):

Solution:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * @author avcbcoder last modified @01-Jun-2018 @9:25:06 PM codeforces div3 -
 *         TODO
 */

public class Solution {
	public static void main(String[] args) throws Exception {
		// while (true)
		solve();
	}

	public static int r00 = -1, r0 = -1, r2 = -1, r5 = -1, r7 = -1;

	// **SOLUTION**
	public static void solve() throws Exception {
		r00 = -1;
		r0 = -1;
		r2 = -1;
		r5 = -1;
		r7 = -1;
		String s = br.readLine();
		int[] c = new int[10];
		for (int i = 0; i < s.length(); i++)
			c[s.charAt(i) - '0']++;
		set(s);
		int min = Integer.MAX_VALUE;
		int _00 = _00(s, c);
		if (_00 != -1)
			min = Math.min(min, _00);
		int _25 = _25(s, c);
		if (_25 != -1)
			min = Math.min(min, _25);
		int _50 = _50(s, c);
		if (_50 != -1)
			min = Math.min(min, _50);
		int _75 = _75(s, c);
		if (_75 != -1)
			min = Math.min(min, _75);
		// System.out.println(_00 + " " + _25 + " " + _50 + " " + _75);
		if (min == Integer.MAX_VALUE)
			System.out.println(-1);
		else
			System.out.println(min);
	}

	private static void set(String s) {
		for (int i = s.length() - 1; i >= 0; i--) {
			int x = s.charAt(i) - '0';
			switch (x) {
			case 0:
				if (r0 == -1)
					r0 = i;
				else if (r00 == -1)
					r00 = i;
				break;
			case 2:
				if (r2 == -1)
					r2 = i;
				break;
			case 5:
				if (r5 == -1)
					r5 = i;
				break;
			case 7:
				if (r7 == -1)
					r7 = i;
				break;
			default:
				break;
			}
		}
	}

	/**
	 * @param s
	 * @param c
	 * @return
	 */
	private static int _75(String s, int[] c) {
		if (c[7] < 1 || c[5] < 1)
			return -1;
		int a = (s.length() - 1) - r5;
		a += (s.length() - 2) - (r7) - ((r7 > r5) ? -1 : 0);
		StringBuilder t = new StringBuilder("");

		for (int i = 0; i < s.length(); i++)
			if (i == r5 || i == r7)
				continue;
			else
				t.append(s.charAt(i));
		// t.append('2');
		// t.append('5');
		String ts = t.toString();
		if (ts.length() == 0)
			return a;
		for (int i = 0; i < ts.length(); i++) {
			if (ts.charAt(i) != '0') {
				a += i;
				return a;
			}
		}
		return -1;
	}

	/**
	 * @param s
	 * @param c
	 * @return
	 */
	private static int _50(String s, int[] c) {
		if (c[5] < 1 || c[0] < 1)
			return -1;
		int a = (s.length() - 1) - r0;
		a += (s.length() - 2) - (r5) - ((r5 > r0) ? -1 : 0);
		StringBuilder t = new StringBuilder("");

		for (int i = 0; i < s.length(); i++)
			if (i == r0 || i == r5)
				continue;
			else
				t.append(s.charAt(i));
		// t.append('2');
		// t.append('5');
		String ts = t.toString();
		if (ts.length() == 0)
			return a;
		for (int i = 0; i < ts.length(); i++) {
			if (ts.charAt(i) != '0') {
				a += i;
				return a;
			}
		}
		return -1;
	}

	/**
	 * @param s
	 * @param c
	 * @return
	 */
	private static int _25(String s, int[] c) {
		if (c[2] < 1 || c[5] < 1)
			return -1;
		int a = (s.length() - 1) - r5;
		// a += (s.length() - 2) - (r2) - ((r2 == s.length() - 1) ? -1 : 0);
		a += (s.length() - 2) - (r2) - ((r2 > r5) ? -1 : 0);
		StringBuilder t = new StringBuilder("");

		for (int i = 0; i < s.length(); i++)
			if (i == r5 || i == r2)
				continue;
			else
				t.append(s.charAt(i));
		// t.append('2');
		// t.append('5');
		String ts = t.toString();
		if (ts.length() == 0)
			return a;
		for (int i = 0; i < ts.length(); i++) {
			if (ts.charAt(i) != '0') {
				a += i;
				return a;
			}
		}
		return -1;
	}

	/**
	 * @param s
	 * @param c
	 * @return
	 */
	private static int _00(String s, int[] c) {
		if (c[0] < 2)
			return -1;
		int a = (s.length() - 1) - r0;
		a += (s.length() - 2) - (r00);
		StringBuilder t = new StringBuilder("");
		for (int i = 0; i < s.length(); i++)
			if (i == r0 || i == r00)
				continue;
			else
				t.append(s.charAt(i));
		String ts = t.toString();
		if (ts.length() == 0)
			return -1;
		return a;
	}

	public static InputStreamReader r = new InputStreamReader(System.in);

	public static BufferedReader br = new BufferedReader(r);

	public static Scanner sc = new Scanner(System.in);
}