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.IOException;
import java.io.InputStreamReader;

public class Main {
	public static int N;
	public static int[] array, original;

	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		String str = f.readLine();
		N = str.length();
		long number = Long.parseLong(str);
		if (number == 25 || number == 50 || number == 75) {
			System.out.println(0);
			return;
		}
		if (number == 52 || number == 57) {
			System.out.println(1);
			return;
		}
		array = new int[N];
		original = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = str.charAt(i) - '0';
			original[i] = array[i];
		}
		int min = 1 << 29;
		min = Math.min(min, check00());
		restore();
		min = Math.min(min, check25());
		restore();
		min = Math.min(min, check50());
		restore();
		min = Math.min(min, check75());
		restore();
		if (min == 1 << 29) {
			min = -1;
		}
		System.out.println(min);
	}

	public static void restore() {
		for (int i = 0; i < N; i++) {
			array[i] = original[i];
		}
	}

	public static int check00() {
		int index1 = -1;
		int index2 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 0) {
				index1 = i;
				break;
			}
		}
		if (index1 == -1)
			return 1 << 29;
		for (int i = index1 - 1; i >= 0; i--) {
			if (array[i] == 0) {
				index2 = i;
				break;
			}
		}
		if (index2 == -1)
			return 1 << 29;
		int res = 0;
		while (index1 != N - 1) {
			swap(index1, index1 + 1);
			index1++;
			res++;
		}
		index2 = -1;
		for (int i = N - 2; i >= 0; i--) {
			if (array[i] == 0) {
				index2 = i;
				break;
			}
		}
		while (index2 != N - 2) {
			swap(index2, index2 + 1);
			index2++;
			res++;
		}
		return res;
	}

	public static int check75() {
		int index7 = -1;
		int index5 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 7) {
				index7 = i;
				break;
			}
		}
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 5) {
				index5 = i;
				break;
			}
		}
		if (index7 == -1 || index5 == -1)
			return 1 << 29;
		int index = -1;
		for (int i = 0; i < N; i++) {
			if (i == index7 || i == index5) {
				continue;
			}
			if (array[i] != 0) {
				index = i;
				break;
			}
		}
		if (index == -1)
			return 1 << 29;
		int res = 0;
		while (index != 0) {
			swap(index, index - 1);
			index--;
			res++;
		}
		index7 = -1;
		index5 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 7) {
				index7 = i;
				break;
			}
		}
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 5) {
				index5 = i;
				break;
			}
		}
		while (index5 != N - 1) {
			swap(index5, index5 + 1);
			index5++;
			res++;
		}
		index7 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 7) {
				index7 = i;
				break;
			}
		}
		while (index7 != N - 2) {
			swap(index7, index7 + 1);
			index7++;
			res++;
		}
		return res;
	}

	public static int check50() {
		int index0 = -1;
		int index5 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 0) {
				index0 = i;
				break;
			}
		}
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 5) {
				index5 = i;
				break;
			}
		}
		if (index0 == -1 || index5 == -1)
			return 1 << 29;
		int index = -1;
		for (int i = 0; i < N; i++) {
			if (i == index5) {
				continue;
			}
			if (array[i] != 0) {
				index = i;
				break;
			}
		}
		if (index == -1)
			return 1 << 29;
		int res = 0;
		while (index != 0) {
			swap(index, index - 1);
			index--;
			res++;
		}
		index0 = -1;
		index5 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 0) {
				index0 = i;
				break;
			}
		}
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 5) {
				index5 = i;
				break;
			}
		}
		while (index0 != N - 1) {
			swap(index0, index0 + 1);
			index0++;
			res++;
		}
		index5 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 5) {
				index5 = i;
				break;
			}
		}
		while (index5 != N - 2) {
			swap(index5, index5 + 1);
			index5++;
			res++;
		}
		return res;
	}

	public static int check25() {
		int index2 = -1;
		int index5 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 2) {
				index2 = i;
				break;
			}
		}
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 5) {
				index5 = i;
				break;
			}
		}
		if (index2 == -1 || index5 == -1)
			return 1 << 29;
		int index = -1;
		for (int i = 0; i < N; i++) {
			if (i == index2 || i == index5) {
				continue;
			}
			if (array[i] != 0) {
				index = i;
				break;
			}
		}
		if (index == -1)
			return 1 << 29;
		int res = 0;
		while (index != 0) {
			swap(index, index - 1);
			index--;
			res++;
		}
		index2 = -1;
		index5 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 2) {
				index2 = i;
				break;
			}
		}
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 5) {
				index5 = i;
				break;
			}
		}
		while (index5 != N - 1) {
			swap(index5, index5 + 1);
			index5++;
			res++;
		}
		index2 = -1;
		for (int i = N - 1; i >= 0; i--) {
			if (array[i] == 2) {
				index2 = i;
				break;
			}
		}
		while (index2 != N - 2) {
			swap(index2, index2 + 1);
			index2++;
			res++;
		}
		return res;
	}

	public static void printArray(int[] array) {
		for (int i : array) {
			System.out.print(i + " ");
		}
		System.out.println();
	}

	public static void swap(int i, int j) {
		int temp = array[i];
		array[i] = array[j];
		array[j] = temp;
	}
}