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:
//package R486Div3;

import java.io.*;
import java.util.*;

public class E {

	static boolean is(int x)
	{
		return (x==25||x==50||x==0||x==75);
	}
	public static void main(String[] args) {
			
		FastScanner s = new FastScanner();
		String g = s.nextString();
		int n = g.length();
		char[] c = g.toCharArray();
		int[] arr = new int[c.length];
		int[] count = new int[10];
		
		for(int i=0;i<g.length();i++)
		{
			arr[i] = g.charAt(i)-'0';
		}
		
		if(g.endsWith("00")||g.endsWith("50")||g.endsWith("25")||g.endsWith("75"))
		{
			System.out.println(0);
			return;
		}
		
		// 25 00 75 50
		int ans = n*n*n;
		int unit=-1,tens=-1;
		for(int i=0;i<c.length;i++)
		{
			boolean flag = false;
			for(int j=0;j<c.length;j++)
			{
				if(j==i)
					continue;
				
				int[] D = Arrays.copyOfRange(arr, 0, c.length);
	
				unit = arr[i];
				tens = arr[j];
				int swaps = 0;
				
			//	System.out.println(i+" "+j);
				
				// if j greater than i, do j first
				// unit--i, tens--j
					
				//unit goes first swapping
				//if tens comes in units path swaps++ happens when      units<=(n-1) 
				// 
				
		//		for(int T=0;T<n;T++)
			//		System.out.print(D[T]+" ");
				//System.out.println();
				for(int k=i;k<n-1;k++)
				{
					int t = D[k];
					D[k] = D[k+1];
					D[k+1] = t;
					swaps++;
					if(j>i&&k==j)
					{
						j--;
						flag = true;
					}
					
				}
				
				for(int k=j;k<n-2;k++)
				{
					int t = D[k];
					D[k] = D[k+1];
					D[k+1] = t;
					swaps++;
				}
			//	if(j>i)
				//	swaps++;
				
				if(is(unit+10*tens))
				{
					if(D[0]!=0)
						ans = Math.min(ans, swaps);
					else
					{
						for(int l=0;l<n;l++)
						{
							if(D[l]!=0&&l<n-2)
							{
								swaps+=l;
								ans = Math.min(swaps,ans);
								break;
							}
						}
					}
				}
				if(flag)j++;
			}
		}
		
		System.out.println(ans==n*n*n?-1:ans);
		
		
		
		
		
	}
static class FastScanner {
		
	    private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		
		}	

	}

}