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.lang.*;
import java.io.*;

public final class Main {
    static int[] memo;
	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in=new Scanner(System.in);
	    int[] stat=new int[10];
	    String[] n=in.next().split("");
	    if(n.length==1&&Integer.parseInt(n[0])==0){
	    System.out.println("0");
	    return;
	    }
	    for(String s:n){
	        stat[Integer.parseInt(s)]++;
	    }
	   int min=Integer.MAX_VALUE;
	   int temp=0;
	   String gg;
	   //case 00
	   String[] t=new String[n.length];
	   for(int k=0;k<t.length;k++){
	       t[k]=n[k];
	   }
	   if(stat[0]>=2){
	       for(int i=n.length-1;i>-1;i--){
	           if(n[i].equals("0")){
	              temp+=n.length-1-i;
	               gg=n[i];
	              for(int j=i;j<n.length-1;j++){
	               
	                n[j]=n[j+1];
	                
	              }
	              n[n.length-1]=gg;
	              break;
	           }
	       }
	        for(int i=n.length-2;i>-1;i--){
	           if(n[i].equals("0")){
	              temp+=n.length-2-i;
	              gg=n[i];
	              for(int j=i;j<n.length-1;j++){
	               
	                n[j]=n[j+1];
	                
	              }n[n.length-2]=gg;
	              break;
	           }
	       }
	         
	      
	       if(!n[0].equals("0")){
	       
	           
	       min=Math.min(min,temp);
	       }
	      else if(n[0].equals("0")){ 
	          int swap=Integer.MAX_VALUE;
	           boolean found=false;
	               for(int i=1;i<n.length;i++)   {
	            if(!n[i].equals("0")){
	                found=true;
	                swap=i;
	                break;
	            }
	        }
	        min=Math.min(min,temp+swap);
	       }
	      
	   }
	      for(int k=0;k<t.length;k++){
	       n[k]=t[k];
	   }
	 //  print(t);
	   //case 25
	   temp=0;
	   if(stat[5]>=1&&stat[2]>=1){
	       for(int i=n.length-1;i>-1;i--){
	           if(n[i].equals("5")){
	              temp+=n.length-1-i;
	               gg=n[i];
	              for(int j=i;j<n.length-1;j++){
	               
	                n[j]=n[j+1];
	                
	              }
	              n[n.length-1]=gg;
	              break;
	           }
	       }//print(n);
	        for(int i=n.length-2;i>-1;i--){
	           if(n[i].equals("2")){
	              temp+=n.length-2-i;
	                  gg=n[i];
	              for(int j=i;j<n.length-1;j++){
	               
	                n[j]=n[j+1];
	                
	              } n[n.length-2]=gg;
	              break;
	           }
	       }
	     //   print(n);  
	        
	       if(!n[0].equals("0")){
	       min=Math.min(min,temp);
	       }
	         else if(n[0].equals("0")){ 
	          int swap=Integer.MAX_VALUE;
	           boolean found=false;
	               for(int i=1;i<n.length;i++)   {
	            if(!n[i].equals("0")){
	                found=true;
	                swap=i;
	                break;
	            }
	        }
	        min=Math.min(min,temp+swap);
	       }
	      
	   }
	        for(int k=0;k<t.length;k++){
	       n[k]=t[k];
	   }
	    //case 75
	   temp=0;
	   if(stat[5]>=1&&stat[7]>=1){
	       for(int i=n.length-1;i>-1;i--){
	           if(n[i].equals("5")){
	              temp+=n.length-1-i;
	                 gg=n[i];
	              for(int j=i;j<n.length-1;j++){
	               
	                n[j]=n[j+1];
	                
	              } n[n.length-1]=gg;
	              break;
	           }
	       }
	        for(int i=n.length-2;i>-1;i--){
	           if(n[i].equals("7")){
	              temp+=n.length-2-i;
	               gg=n[i];
	              for(int j=i;j<n.length-1;j++){
	               
	                n[j]=n[j+1];
	                
	              } n[n.length-2]=gg;
	              break;
	           }
	       }   
	        
	       if(!n[0].equals("0")){
	       min=Math.min(min,temp);
	       }  else if(n[0].equals("0")){ 
	          int swap=Integer.MAX_VALUE;
	           boolean found=false;
	               for(int i=1;i<n.length;i++)   {
	            if(!n[i].equals("0")){
	                found=true;
	                swap=i;
	                break;
	            }
	        }
	        min=Math.min(min,temp+swap);
	       }
	      
	   }
	        for(int k=0;k<t.length;k++){
	       n[k]=t[k];
	   }
	    //case 50
	   temp=0;
	   if(stat[5]>=1&&stat[0]>=1){
	       for(int i=n.length-1;i>-1;i--){
	           if(n[i].equals("0")){
	              temp+=n.length-1-i;
	             gg=n[i];
	              for(int j=i;j<n.length-1;j++){
	               
	                n[j]=n[j+1];
	                
	              }n[n.length-1]=gg;
	              break;
	           }
	       }
	        for(int i=n.length-2;i>-1;i--){
	           if(n[i].equals("5")){
	              temp+=n.length-2-i;
	            gg=n[i];
	              for(int j=i;j<n.length-1;j++){
	               
	                n[j]=n[j+1];
	                
	              } n[n.length-2]=gg;
	              break;
	           }
	       } 
	      
	        
	       if(!n[0].equals("0")){
	       min=Math.min(min,temp);
	       }  
	       else if(n[0].equals("0")){ 
	          int swap=Integer.MAX_VALUE;
	           boolean found=false;
	               for(int i=1;i<n.length;i++)   {
	            if(!n[i].equals("0")){
	                found=true;
	                swap=i;
	                break;
	            }
	        }
	        min=Math.min(min,temp+swap);
	       }
	      
	   
	   }
	  if(min<Integer.MAX_VALUE)
	   System.out.println(min);
	   else
   System.out.println("-1");
	   
	   
	}
private static void print(String[] args){
    for(String s:args)
    System.out.print(s);
    System.out.println();
    
}
}