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.ArrayList;
import java.util.Scanner;

public class cf
{

	static ArrayList[] adj;
	static int[] visited;
	static int ans = 0;

	public static void main(String[] args)
	{

		Scanner in = new Scanner(System.in);

		String s = in.nextLine();

		int min = Integer.MAX_VALUE;

		if (Long.parseLong(s) < 25)
		{
			System.out.println(-1);
			System.exit(0);
		}

		int ans = 0;
		int f = 0;
		for (int i = s.length() - 1; i >= 0; i--)
		{
			if (s.charAt(i) == '0')
			{
				ans += s.length() - i - 1;
				f++;
			}

			if (f == 2)
			{
				break;
			}
		}
		if (f == 2)
			min = Math.min(min, ans - 1);

		ans = 0;
		int a = 0;
		int b = 0;

		f = 0;
		int g = 0;

		for (int i = s.length() - 1; i >= 0; i--)
		{
			if (f == 0 && s.charAt(i) == '2')
			{
				a = s.length() - i - 1;
				f = 1;
			}

			if (g == 0 && s.charAt(i) == '5')
			{
				b = s.length() - i - 1;
				g = 1;
			}
		}

		String t = "";

		if (f != 0 && g != 0)
		{
			if (b > a)
			{
				ans = 1;
				t = s.substring(0, s.length() - 1 - b) + s.substring(s.length() - b, s.length() - 1 - a)
						+ s.substring(s.length() - a) + "25";
			} else
			{
				t = s.substring(0, s.length() - 1 - a) + s.substring(s.length() - a, s.length() - 1 - b)
						+ s.substring(s.length() - b) + "25";
			}

			for (int i = 0; i < t.length(); i++)
			{
				if (t.charAt(i) == '0')
				{
					ans++;
				} else
				{
					break;
				}
			}

			ans += a - 1 + b;
			min = Math.min(min, ans);
		}

		ans = 0;
		a = 0;
		b = 0;

		f = 0;
		g = 0;

		for (int i = s.length() - 1; i >= 0; i--)
		{
			if (f == 0 && s.charAt(i) == '5')
			{
				a = s.length() - i - 1;
				f = 1;
			}

			if (g == 0 && s.charAt(i) == '0')
			{
				b = s.length() - i - 1;
				g = 1;
			}
		}

		if (f != 0 && g != 0)
		{
			t = "";
			if (b > a)
			{
				ans = 1;
				t = s.substring(0, s.length() - 1 - b) + s.substring(s.length() - b, s.length() - 1 - a)
						+ s.substring(s.length() - a) + "50";
			} else
			{
				t = s.substring(0, s.length() - 1 - a) + s.substring(s.length() - a, s.length() - 1 - b)
						+ s.substring(s.length() - b) + "50";
			}

			for (int i = 0; i < t.length(); i++)
			{
				if (t.charAt(i) == '0')
				{
					ans++;
				} else
				{
					break;
				}
			}
			ans += a - 1 + b;
			min = Math.min(min, ans);
		}

		ans = 0;
		a = 0;
		b = 0;

		f = 0;
		g = 0;

		for (int i = s.length() - 1; i >= 0; i--)
		{
			if (f == 0 && s.charAt(i) == '7')
			{
				a = s.length() - i - 1;
				f = 1;
			}

			if (g == 0 && s.charAt(i) == '5')
			{
				b = s.length() - i - 1;
				g = 1;
			}
		}

		if (f != 0 && g != 0)
		{
			t = "";
			if (b > a)
			{
				ans = 1;
				t = s.substring(0, s.length() - 1 - b) + s.substring(s.length() - b, s.length() - 1 - a)
						+ s.substring(s.length() - a) + "75";
			} else
			{
				t = s.substring(0, s.length() - 1 - a) + s.substring(s.length() - a, s.length() - 1 - b)
						+ s.substring(s.length() - b) + "75";
			}

			for (int i = 0; i < t.length(); i++)
			{
				if (t.charAt(i) == '0')
				{
					ans++;
				} else
				{
					break;
				}
			}

			ans += a - 1 + b;
			min = Math.min(min, ans);
		}

		if (min == Integer.MAX_VALUE)
		{
			min = -1;
		}

		System.out.println(min);

	}

	public static int dfs(int i)
	{
		if (visited[i] == 1)
		{
			return 0;
		}

		visited[i] = 1;

		int sum = 1;

		for (int j = 0; j < adj[i].size(); j++)
		{
			sum += (int) dfs((int) adj[i].get(j));
		}

		if (sum % 2 == 0)
		{
			ans++;
			return 0;
		}

		return sum;
	}

}