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.util.*;
import java.io.*;

public class Divisibilityby25 {

	static final int INF = Integer.MAX_VALUE / 2;

	boolean isDivisible(Dummy s) {
		char[] a = s.s.toCharArray();
		int l = a.length;
		if (a[l - 2] == '0' && a[l - 1] == '0')
			return true;
		if (a[l - 2] == '2' && a[l - 1] == '5')
			return true;
		if (a[l - 2] == '5' && a[l - 1] == '0')
			return true;
		if (a[l - 2] == '7' && a[l - 1] == '5')
			return true;

		return false;

	}

	int countOccurences(Dummy s, char c) {
		char[] a = s.s.toCharArray();
		int cnt = 0;
		for (int i = 0; i < a.length; i++) {
			if (a[i] == c)
				cnt++;
		}
		return cnt;

	}

	static class Dummy {
		String s;

		Dummy(String s) {
			this.s = s;
		}
	}

	void solve(Scanner in, PrintWriter out) {
		String ip = in.next();
		Dummy s = new Dummy(ip);

		char[] a = s.s.toCharArray();
		int l = a.length;
		if ((countOccurences(s, '2') == 0 && countOccurences(s, '5') == 0)
				&& (countOccurences(s, '5') == 0 && countOccurences(s, '0') == 0)
				&& (countOccurences(s, '7') == 0 && countOccurences(s, '5') == 0) && (countOccurences(s, '0') <= 1)) {
			out.println(-1);
		} else {

			int min = INF;

			if (isDivisible(s))
				out.println(0);
			else {
				// make 00
				if (countOccurences(s, '0') >= 2) {

					Dummy s1 = new Dummy(new String(ip));
					// out.println("making 00");

					int m = countMoves(s1, '0', out);
					// out.println(" 0 " + m + " modString " + s1.s);
					m += countMoves(s1, '0', out);
					// out.println(" 0 " + m + " modString " + s1.s);
					min = Math.min(min, m);
				}

				// make 25
				if ((countOccurences(s, '2') > 0 && countOccurences(s, '5') > 0)) {

					Dummy s1 = new Dummy(new String(ip));
				//	out.println("making 25");
					int m = countMoves(s1, '5', out);
					//out.println(" 5 " + m + " modString " + s1.s);
					m += countMoves(s1, '2', out);
				//	out.println(" 2 " + m + " modString " + s1.s);
					min = Math.min(min, m);
				}

				// make 50

				if (countOccurences(s, '5') > 0 && countOccurences(s, '0') > 0) {
					// out.println("making 50");

					Dummy s1 = new Dummy(new String(ip));
					int m = countMoves(s1, '0', out);
					// out.println(" 0 " + m + " modString " + s1.s);
					m += countMoves(s1, '5', out);
					// out.println(" 5 " + m + " modString " + s1.s);
					min = Math.min(min, m);
				}

				// make 75
				if (countOccurences(s, '7') > 0 && countOccurences(s, '5') > 0) {

					// out.println("making 75");
					Dummy s1 = new Dummy(new String(ip));
					int m = countMoves(s1, '5', out);
					// out.println(" 5 " + m + " modString " + s1.s);
					m += countMoves(s1, '7', out);
					// out.println(" 7 " + m + " modString " + s1.s);
					min = Math.min(min, m);
				}

				if (min >= INF)
					out.println(-1);
				else
					out.println(min);

			}

		}

	}

	private int countMoves(Dummy s, char c, PrintWriter out) {

		int ix = s.s.lastIndexOf(c);
		int l = s.s.length();
		if (ix == s.s.length())
			return 0;
		else {

			if (ix != 0 || (ix == 0 & s.s.length() == 1 && s.s.charAt(0) != '0')) {
				StringBuffer sb = new StringBuffer(s.s);
				sb.deleteCharAt(ix);
				s.s = sb.toString();
				// out.println(s.s);
				return l - ix - 1;
			} else {
				Dummy ns = new Dummy(s.s.substring(1));
				if (countOccurences(ns, '0') == ns.s.length())
					return INF;
				else {

					StringBuffer sb = new StringBuffer(ns.s);

					for (int i = 0; i < ns.s.length(); i++)
						if (ns.s.charAt(i) != '0') {
							char t = sb.charAt(i);
							sb.deleteCharAt(i);
							sb.insert(0, s.s.charAt(0) + "");
							sb.insert(0, t + "");

							s.s = sb.toString();
							// out.println("ns.s" + s.s);
							int m = countMoves(s, c, out);
							// out.println(" m in prob"+ m);
							return i + 1 + m;
						}

				}

			}
			return INF;

		}

	}

	void run() {
		try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);) {
			solve(in, out);
		}
	}

	public static void main(String args[]) {
		new Divisibilityby25().run();
	}
}