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 R486E {
	
	/*
	Try edge cases
	100
	25
	52
	520
	2605
	2065
	 */

	public static void main(String[] args) {
		JS scan = new JS();
		char[] num = scan.next().toCharArray();
		int[] freq = new int[10];
		int n = num.length;
		if(n < 2) {
			System.out.println("-1");
			return;
		}
		for(int i = 0; i < n; i++)
			freq[num[i]-'0']++;
		int ans = Integer.MAX_VALUE;
		if(freq[0] >= 2) {
			char[] cpy = new char[n];
			for(int i = 0; i < n; i++) cpy[i] = num[i];
			int swaps = 0;
			for(int i = n-1; i >= 0; i--) {
				if(cpy[i] == '0') {
					swaps += n-1-i;
					for(int j = i; j <= n-2; j++) {
						char temp = cpy[j];
						cpy[j] = cpy[j+1];
						cpy[j+1] = temp;
					}
					break;
				}
			}
			for(int i = n-2; i >= 0; i--) {
				if(cpy[i] == '0') {
					swaps += n-2-i;
					for(int j = i; j <= n-3; j++) {
						char temp = cpy[j];
						cpy[j] = cpy[j+1];
						cpy[j+1] = temp;
					}
					break;
				}
			}
			ans = Math.min(ans, swaps);
		}
		if(freq[5] >= 1 && freq[2] >= 1) {
			ans = Math.min(ans, check('5', '2', num));
		}
		if(freq[5] >= 1 && freq[0] >= 1) {
			ans = Math.min(ans, check('0', '5', num));
		}
		if(freq[5] >= 1 && freq[7] >= 1) {
			ans = Math.min(ans, check('5', '7', num));
		}
		
		if(ans == Integer.MAX_VALUE) System.out.println(-1);
		else System.out.println(ans);
	}
	//1257550
	//1207550
	//1255075
	static int check(char first, char second, char[] num) {
		int n = num.length;
		char[] cpy = new char[n];
		for(int i = 0; i < n; i++) cpy[i] = num[i];
		int swaps = 0;
		//Swaps for first
		
		for(int i = n-1; i >= 0; i--) {
			if(cpy[i] == first) {
				for(int j = i; j <= n-2; j++) {
					char temp = cpy[j];
					cpy[j] = cpy[j+1];
					cpy[j+1] = temp;
				}
				swaps += n-1-i;
				break;
			}
		}
		
		//Swaps for second
		
		for(int i = n-2; i >= 0; i--) {
			if(cpy[i] == second) {
				for(int j = i; j <= n-3; j++) {
					char temp = cpy[j];
					cpy[j] = cpy[j+1];
					cpy[j+1] = temp;
				}
				swaps += n-2-i;
				break;
			}
		}
		
		//Swaps in case of leading zero
		
		int f = 0;
		if(cpy[0] != '0') f = 1;
		for(int i = 0; i < n-2; i++) {
			if(cpy[i] != '0') {
				swaps += i;
				f = 1;
				break;
			}
		}
		
		if(f == 1) return swaps;
		return Integer.MAX_VALUE;
		
	}
	
	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}				
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}