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.

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

public class Codechef
{
   
    //static boolean vis[];
    int max = (int)1e5+1;
    static ArrayList<Integer>graph[];
    static int q_v[];
    static ArrayList<Integer>qs[];
    static int q_c[];
    static char arr[];
    static int temp[];
	public static void main (String[] args) throws java.lang.Exception
	{
	    InputReader input = new InputReader(System.in);
	    OutputWriter out = new OutputWriter(System.out);
	    HashMap<Integer,Integer>map1 = new HashMap<Integer,Integer>();
	    
	    String n = input.readString();
	    
        int res = Integer.MAX_VALUE;
        int z = n.length();
        //System.out.println(z);
        for(int i =0;i<z;i++){
            for(int j = 0;j<z;j++){
                if(i == j)continue;
                arr = n.toCharArray();
                int cur = 0;
                for(int x=i;x<z-1;x++){
                    swap(x,x+1);
                    cur++;
                }
                for(int x=j-((j>i)?1:0);x<z-2;x++){
                    swap(x,x+1);
                    cur++;
                }
                int p = -1;
                for(int x=0;x<z;x++){
                    if(arr[x] != '0'){
                        p = x;
                        break;
                    }
                }
                for(int x = p;x>0;x--){
                    swap(x,x-1);
                    cur++;
                }
                String s = "";
                s+=arr[z-2];
                s+=arr[z-1];
                if(Integer.parseInt(s)%25 == 0){
                    res = Math.min(res,cur);
                }
            }
        }
        if(res == Integer.MAX_VALUE)System.out.println(-1);
        else System.out.println(res);
	}
	public static void swap(int x,int y){
	    char t = arr[x];
	    arr[x] = arr[y];
	    arr[y] = t;
	}
	public static void reverse(int z){
	    int a[] = new int[20];
	    int x =0;
	    for(int i = z-1;i>=0;i--){
	        a[x++] = arr[i];
	    }
	    System.arraycopy(a,0,arr,0,z);
	}
}
 class InputReader{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
		
		public int read() {
			if (numChars == -1) {
				throw new InputMismatchException();
			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}
		
		public int readInt() {
			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 String readString() {
			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 double readDouble() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E') {
					return res * Math.pow(10, readInt());
				}
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E') {
						return res * Math.pow(10, readInt());
					}
					if (c < '0' || c > '9') {
						throw new InputMismatchException();
					}
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
		
		public long readLong() {
			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 boolean isSpaceChar(int c) {
			if (filter != null) {
				return filter.isSpaceChar(c);
			}
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		
		public String next() {
			return readString();
		}
		
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
	
 class OutputWriter {
		private final PrintWriter writer;
		
		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}
		
		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}
		
		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
			writer.flush();
		}
		
		public void printLine(Object... objects) {
			print(objects);
			writer.println();
			writer.flush();
		}
		
		public void close() {
			writer.close();
		}
		
		public void flush() {
			writer.flush();
		}
	}
	   
//********************************************************************************************************************************
//////////////////////////////////NOTESSS//////////////////////////////////////////////////////////////////////
/*remember substring length you are dealing with take only those substrings
chain like pattern -> linked list (or) to from Arrays
finding degree can be done during input scanning itself(ok&=true:false flag trick)
longest subsquence can be solved in O(n) itself incase of consecutive numbers why try all subsequence go o dp[i-1]
(*******consecutive numberssssss*********)
initialize all global variables and collection ds
swapping changes the arr so make sure initialize with the original again
*/
