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.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String nStr = in.next();
			long n = Long.parseLong(nStr);
			if (n % 25 == 0) {
				out.println(0);
				return;
			}
			// 00 25 50 75
			Set<Character> cs = new HashSet<>();
			int count0 = 0;
			for (char c : nStr.toCharArray()) {
				if (c == '0') {
					count0++;
				}
				cs.add(c);
			}
			List<String> list = new ArrayList<>();
			int len = nStr.length();
			list.add(nStr);
			if ((count0 >= 2) || (cs.contains('5') && (cs.contains('2') || cs.contains('0') || cs.contains('7')))) {
				String end2 = nStr.substring(len - 2, len);
				StringBuilder sb = new StringBuilder(end2);
				sb.reverse();
				if (sb.toString().equals("00") || sb.toString().equals("25") || sb.toString().equals("50") || sb.toString().equals("75")) {
					out.println(1);
					return;
				}
				int index01 = 20;
				int index02 = 20;

				int index5 = 20;

				int index2 = 20;
				int index7 = 20;
				for (int i = nStr.length() - 1; i >= 0; i--) {
					switch (nStr.charAt(i)) {
					case '0':
						if (index01 == 20) {
							index01 = i;
						} else if (index02 == 20) {
							index02 = i;
						}
						break;
					case '2':
						if (index2 == 20) {
							index2 = i;
						}
						break;
					case '5':
						if (index5 == 20) {
							index5 = i;
						}
						break;
					case '7':
						if (index7 == 20) {
							index7 = i;
						}
						break;
					default:
						break;
					}
				}
				int moves = len * len;
				if (index01 < 20 && index02 < 20) {
					int m1 = len - index01 - 1;
					int m2 = len - index02 - 2;
					if (moves > m1 + m2) {
						moves = m1 + m2;
					}
				}
				if (index5 < 20 && index01 < 20) {
					StringBuilder sbt = new StringBuilder(nStr);
					int m1;
					int m2;
					if (index01 > index5) {
						m1 = len - index01 - 1;
						m2 = len - index5 - 2;
						sbt.deleteCharAt(index01);
						sbt.deleteCharAt(index5);
					} else {
						m1 = len - index5 - 1;
						m2 = len - index01 - 2;
						m2++;
						sbt.deleteCharAt(index5);
						sbt.deleteCharAt(index01);
					}

					int start0 = 0;
					for (int i = 0; i < sbt.length(); i++) {
						if (sbt.charAt(i) == '0') {
							start0++;
						} else {
							break;
						}
					}
					int move = m1 + m2 + start0;
					if (move < moves) {
						moves = move;
					}
				}
				if (index2 < 20 && index5 < 20) {
					StringBuilder sbt = new StringBuilder(nStr);
					int m1;
					int m2;
					if (index5 > index2) {
						m1 = len - index5 - 1;
						m2 = len - index2 - 2;
						sbt.deleteCharAt(index5);
						sbt.deleteCharAt(index2);
					} else {
						m1 = len - index2 - 1;
						m2 = len - index5 - 2;
						m2++;
						sbt.deleteCharAt(index2);
						sbt.deleteCharAt(index5);
					}

					int start0 = 0;
					for (int i = 0; i < sbt.length(); i++) {
						if (sbt.charAt(i) == '0') {
							start0++;
						} else {
							break;
						}
					}
					int move = m1 + m2 + start0;
					if (move < moves) {
						moves = move;
					}
				}
				if (index5 < 20 && index7 < 20) {
					StringBuilder sbt = new StringBuilder(nStr);
					int m1;
					int m2;
					if (index5 > index7) {
						m1 = len - index5 - 1;
						m2 = len - index7 - 2;
						sbt.deleteCharAt(index5);
						sbt.deleteCharAt(index7);
					} else {
						m1 = len - index7 - 1;
						m2 = len - index5 - 2;
						m2++;
						sbt.deleteCharAt(index7);
						sbt.deleteCharAt(index5);
					}
					int start0 = 0;
					for (int i = 0; i < sbt.length(); i++) {
						if (sbt.charAt(i) == '0') {
							start0++;
						} else {
							break;
						}
					}
					int move = m1 + m2 + start0;
					if (move < moves) {
						moves = move;
					}
				}
				out.println(moves);
			} else {
				out.println(-1);
				return;
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public Long nextLong() {
			return Long.parseLong(next());
		}

	}
}