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.*;
import java.math.BigInteger;
import java.util.*;

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

	static class Task {
		public void solve(InputReader in, PrintWriter out) throws IOException {
			long tStart = System.currentTimeMillis();

//			int arr[][] = {
//				{1,2,3},{0},{0},{0}
//			};
			
//			int arr[][] = {
//					{1},{0,2,4},{1,3,4},{2},{1,2}	
//			};
			
			String x = in.next();
			char arr[] = x.toCharArray();
			int n = x.length();
			if(n<2) {
				out.println(-1);
				return;
			}
			int t = dfs(arr,n-1);			
			out.println(t==100?-1:t);
			//Dumper.print(shortestPathLength(arr));
			long tEnd = System.currentTimeMillis();
			long tDelta = tEnd - tStart;
			double elapsedSeconds = tDelta / 1000.0;
			//Dumper.print(elapsedSeconds);
		}
		int dfs(char arr[], int p) {
			if(p<arr.length-2) return 0;
			int min = 100;
			char copy[] = arr.clone();
			for(int i=p;i>=0;i--) {
				if(p==arr.length-1) {
					if(arr[i]=='0'||arr[i]=='5') {
						int d = swap(arr,i,p);
						min = Math.min(min, dfs(arr,p-1)+d);					
						//min = Math.min(min, dfs(arr,p-1)+d);
					}
				}else if(p==arr.length-2) {
					if(arr[arr.length-1]=='0') {
						if(arr[i]=='0'||arr[i]=='5') {
							int d = swap(arr,i,p);
							int t = extra_swap(arr);
							min = Math.min(min, t+d);
						}
					}else if(arr[arr.length-1]=='5'){
						if(arr[i]=='2'||arr[i]=='7') {
							int d = swap(arr,i,p);
							int t = extra_swap(arr);
							min = Math.min(min, t+d);
						}					
					}
				}
				arr = copy.clone();
			}
			return min;
		}
		
		int swap(char[] arr, int i, int j) {	
			char tmp = arr[i];
			for(int k=i;k<j;k++) {
				arr[k] = arr[k+1];
			}
			arr[j] = tmp;
			return j-i;
		}
		int extra_swap(char[] arr) {
			if(arr[0]!='0') return 0;
			else {
				for(int i=1;i<arr.length-2;i++){
					if(arr[i]!='0') return i;
				}
			}
			return 100;
		}
		
		class myString implements Comparable<myString>{
			String val;
			public myString(String a) {
				val = a;
			}
			@Override
			public int compareTo(myString t) {
				return this.val.length()-t.val.length();
			}
		}
		
//	    public int shortestPathLength(int[][] graph) {
//	        int n = graph.length;
//	        if(n==1) return 0;
//	        int g[][] = new int[n][n];
//	        for(int i=0;i<n;i++){
//	        	Arrays.fill(g[i], 99999999);
//	        	g[i][i] = 0;
//	        	for(int j:graph[i]){
//	        		g[i][j] = 1;
//	        	}
//	        }	        
//	        for(int k=0;k<n;k++){
//	        	for(int i=0;i<n;i++){
//	        		for(int j=0;j<n;j++){
//	        			g[i][j] = Math.min(g[i][j], g[i][k]+g[k][j]);
//	        		}
//	        	}
//	        }
//	        int p[][] = new int[1<<n][n];	        
//	        int target = 1<<n; target--;
//	        for(int i=0;i<p.length;i++){	
//	        	Arrays.fill(p[i], 99999999);
//	        }
//	        int min = 99999999;
//	        for(int i=0;i<n;i++){
//	        	min = Math.min(min, dp(g,p,(1<<n)-1),i);
//	        }      
////	        for(int i=0;i<p.length;i++) {
////	        	System.out.println(Integer.toBinaryString(i)+" "+p[i]);
////	        }
//	        
//	        //Dumper.print_2d_arr(g, n, n);
//	        //Dumper.print_int_arr(p);
//	        return min;
//	    }		
//	    int dp(int[][] g, int[][] p, int status, int cur){
//	    	if(p[status][cur]<=step) return;
//	    	if(status==target) {
//	    		//Dumper.print(step);
//	    		p[status][cur] = step;
//	    		return;
//	    	}	    
//	    	int min = 99999999
//	    	for(int i=0;i<g.length;i++){
//	    		if(g[cur][i]==0||(status & (1L << i)) != 0) continue;
//	    		min = Math.min(min,dp(g,p,status|(1<<i),i)+g[cur][i]);
//	    	}
//	    	return p[status][cur] = min;	    	
//	    }		
	    	
		class NumArray {
			int n;
			int arr[];
		    public NumArray(int[] nums) {
		        int sz = nums.length;
		        n = 1;
		        while(n<sz) n*=2;
		        arr = new int[n*2-1];		
		        for(int i=0;i<sz;i++) update(i,nums[i]);
		    }
		    
		    public void update(int i, int val) {
		        i+=n-1;
		        arr[i] = val;
		        while(i>0) {
		        	i=(i-1)/2;
		        	arr[i] = arr[i*2+1]+arr[i*2+2];
		        }
		    }
		    
		    public int sumRange(int i, int j) {
		        return sum(i,j+1,0,0,n);
		    }
		    private int sum(int p, int q, int k, int i, int j) {
		    	if(p<=i&&j<=q) return arr[k];
		    	else if(j<=p||i>=q) return 0;
		    	else {
		    		return sum(p,q,k*2+1,i,i+(j-i)/2)+sum(p,q,k*2+2,i+(j-i)/2,j);
		    	}
		    }
		}		
		
	    public List<Integer> fallingSquares(int[][] positions) {
	        int n = positions.length;
	        ArrayList<Integer> arr = new ArrayList<Integer>();
	        for(int i=0;i<n;i++){
	        	arr.add(positions[i][0]);
	        	arr.add(positions[i][0]+positions[i][1]-1);
	        }
	        Collections.sort(arr);	        
	        HashMap<Integer, Integer> mp = new HashMap<Integer,Integer>();
	        for(int i=0,j=0;i<arr.size();i++){
	        	if(!mp.containsKey(arr.get(i))){
	        		mp.put(arr.get(i),j++);
	        	}
	        }
	        int square[][] = new int[n][3];
	        for(int i=0;i<n;i++){
	        	square[i][0] = mp.get(positions[i][0]);
	        	square[i][1] = mp.get(positions[i][0]+positions[i][1]-1); 
	        	square[i][2] = positions[i][1];
	        }
	        List<Integer> result = new ArrayList<Integer>();
	        seg_tree t = new seg_tree(mp.size());
	        int tmp_v = 1;
    		while(tmp_v<mp.size()) {
    			tmp_v*=2;
    		}	        
	        for(int i=0;i<n;i++){
	        	int tmp = t.query1(square[i][0], square[i][1]+1, 0, 0, tmp_v);
	        	System.out.println(tmp);
	        	t.update(square[i][0], square[i][1]+1, 0, 0, tmp_v, square[i][2]+tmp);	        	
	        	tmp = t.query(0,tmp_v, 0, 0, tmp_v);
	        	result.add(tmp);
	        }
	        return result;
	    }
	    class seg_tree{
	    	int n;
	    	int arr_leaf[];
	    	int arr_node[];
	    	public seg_tree(int x) {
	    		n=1;	    		
	    		while(n<x) {
	    			n*=2;
	    		}
	    		arr_leaf = new int[2*n-1];
	    		arr_node = new int[2*n-1];
	    	}
	    	public int update(int a, int b, int k, int i, int j, int v) {
	    		if(a<=i&&j<=b) {
	    			arr_leaf[k]=v;	   
	    			return arr_leaf[k];
	    		}else if(i<b&&a<j){
	    			int t1 = update(a,b,k*2+1,i,(i+j)/2,v);
	    			int t2 = update(a,b,k*2+2,(i+j)/2,j,v);
	    			arr_node[k] = Math.max(arr_node[k], Math.max(t1, t2));
	    			return arr_node[k];
	    		}else {
	    			return 0;
	    		}
	    	}
	    	public int query(int a, int b, int k, int i, int j) {
	    		if(b<=i||j<=a) {
	    			return 0;
	    		}else if(a<=i&&j<=b) {
	    			if(arr_leaf[k]!=0) return arr_leaf[k];
	    			else return arr_node[k];
	    		}else {
	    			int t1 = query(a,b,k*2+1,i,(i+j)/2);
	    			int t2 = query(a,b,k*2+2,(i+j)/2,j);
	    			return Math.max(t1,t2);
	    		}	    		
	    	}
	    	public int query1(int a, int b, int k, int i, int j) {
	    		if(b<=i||j<=a) {
	    			return 0;
	    		}else if(a<=i&&j<=b) {
	    			return arr_leaf[k];
	    		}else {
	    			if(arr_leaf[k]!=0) return arr_leaf[k];
	    			int t1 = query1(a,b,k*2+1,i,(i+j)/2);
	    			int t2 = query1(a,b,k*2+2,(i+j)/2,j);
	    			return Math.max(t1,t2);
	    		}	    		
	    	}	    	
	    }
	      
		class TreeNode {
			int val;
			TreeNode left;
			TreeNode right;

			public TreeNode(int a) {
				val = a;
			}
		}
	}

	// default class
	static class InputReader {
		public BufferedReader re;
		public StringTokenizer st;

		public InputReader(InputStream input) {
			re = new BufferedReader(new InputStreamReader(input));
			st = null;
		}

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

			}
			return st.nextToken();
		}

		public String nextLine() {
			String tmp = null;
			try {
				tmp = re.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			return tmp;
		}

		public boolean hasNext() {
			String tmp;
			if (st != null && st.hasMoreTokens())
				return true;
			else {
				try {
					tmp = re.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (tmp != null) {
					st = new StringTokenizer(tmp);
					return true;
				} else {
					return false;
				}
			}

		}

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}

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

	static class Dumper {
		static void print_int_arr(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}
		
		static void print_char_arr(char[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}		

		static void print_double_arr(double[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}

		static void print_2d_arr(int[][] arr, int x, int y) {
			for (int i = 0; i < x; i++) {
				for (int j = 0; j < y; j++) {
					System.out.print(arr[i][j] + " ");
				}
				System.out.println();
			}
			System.out.println();
			System.out.println("---------------------");
		}

		static void print_2d_arr(boolean[][] arr, int x, int y) {
			for (int i = 0; i < x; i++) {
				for (int j = 0; j < y; j++) {
					System.out.print(arr[i][j] + " ");
				}
				System.out.println();
			}
			System.out.println();
			System.out.println("---------------------");
		}

		static void print(Object o) {
			System.out.println(o.toString());
		}

		static void getc() {
			System.out.println("here");
		}
	}
}