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.IOException;
	import java.io.InputStream;
	import java.io.PrintWriter;
	import java.util.ArrayList;
	import java.util.HashSet;
	import java.util.InputMismatchException;
	import java.util.*;
	public class Tester {
	
		public static void main(String[] args) {
			 int mod = (int) (1e9 + 7);
			 InputReader in = new InputReader(System.in);
			 PrintWriter out = new PrintWriter(System.out);
			 
			 String n = in.nextLine();
			 int p1 = -1, p2 = -1, p3 = -1, p4 = -1, p5=-1;
			 for(int i=n.length()-1;i>=0;i--) {
				 int c = n.charAt(i) - '0';
				 //out.println(c);
				 if(c==0 && (p1==-1 || p5==-1)) {
					 if(p1==-1)
						 p1 = i;
					 else {
						 p5 = i;
					 }
				 }
				 if(c==5 && p2==-1) {
					 p2 = i;
				 }
				 if(c==7 && p3==-1) {
					 p3 = i;
				 }
				 if(c==2 && p4==-1) {
					 p4 = i;
				 }
			 }
			 //out.println(p1 + " " +p2 + " " + p3+ " " + p4);
			 int swap = Integer.MAX_VALUE;
			 
			 if(p1!=-1 && p5!=-1) {
				 int tmp = 2*n.length() - p1 - p5 - 3;
				 if(tmp<swap) {
					 swap = tmp;
				 }
			 }
			 
			 if(n.length()==2) {
				 int num = Integer.parseInt(n);
				 if(num==25 || num==50 || num==75)
					 out.println(0);
				 else {
					 int n1 = n.charAt(0) -'0';
					 int n2 = n.charAt(1) -'0';
					 if(n2==0 && n1 == 5)
						 out.println(0);
					 else if(n2==5 && n1==2) {
						 out.println(0);
					 }
					 else if(n2==2 && n1==5) {
						 out.println(1);
					 }
					 else if(n2==5 && n1==7) {
						 out.println(0);
					 }
					 else if(n2==7 && n1==5) {
						 out.println(1);
					 }
					 else {
						 out.println(-1);
					 }
				 }
					 
				 
			 } 
			 else {
			 if(p1!=-1 && p2!=-1) {
				 //int tmp = 2*n.length() - p1 - p2 - 3;
				 int tmp = 0;
				 StringBuilder str = new StringBuilder(n);
				 str.deleteCharAt(p1);
				 str.append('0');
				 int p = p2;
				 tmp += n.length() - p1 - 1;
				 for(int i=n.length()-1;i>=0;i--) {
					 if(str.charAt(i)=='5') {
						 p = i;
						 str.deleteCharAt(i);
						 break;
					 }
				 }
				 tmp += n.length() - 1 - p - 1;
				 //str.deleteCharAt(str.length()-1);
				 str.deleteCharAt(str.length()-1);
				 boolean poss = true;
				 if(str.charAt(0)=='0') {
					 poss = false;
					 int ind = 1;
					 while(ind<str.length()) {
						 if(str.charAt(ind)!='0') {
							 poss = true;
							 tmp += ind;
							 break;
						 }
						 ind++;
					 } 
				 }
				 if(poss) {
					 if(tmp<swap) {
						 swap = tmp;
					 }
				 }
			 }
			 
			 if(p2!=-1 && p4!=-1) {
				 //out.println(p2 + " " +p4);
				 //int tmp = 2*n.length() - p2 - p4 - 3;
				 int tmp = 0;
				 StringBuilder str = new StringBuilder(n);
				 str.deleteCharAt(p2);
				 str.append('5');
				 int p = p2;
				 tmp += n.length() - p2 - 1;
				 for(int i=n.length()-1;i>=0;i--) {
					 if(str.charAt(i)=='2') {
						 p4 = i;
						 str.deleteCharAt(i);
						 break;
					 }
				 }
				 tmp += n.length() - 1 - p4 - 1;
				 //str.deleteCharAt(str.length()-1);
				 str.deleteCharAt(str.length()-1);
					 
				 boolean poss = true;
				 if(str.charAt(0)=='0') {
					 poss = false;
					 int ind = 1;
					 while(ind<str.length()) {
						 if(str.charAt(ind)!='0') {
							 poss = true;
							 tmp += ind;
							 break;
						 }
						 ind++;
					 }
					 
				 }
				 if(poss) {
					 if(tmp<swap) {
						 swap = tmp;
					 }
				 }
			 }
			 
			 if(p3!=-1 && p2!=-1) {
				 //int tmp = 2*n.length() - p3 - p2 - 3;
				 //out.println();
				 //out.println(tmp);
				 StringBuilder str = new StringBuilder(n);
				 //str.deleteCharAt(p3);
				 //str.deleteCharAt(p2);
				 int tmp = 0;
				 //StringBuilder str = new StringBuilder(n);
				 str.deleteCharAt(p2);
				 str.append('5');
				 tmp += n.length() - p2 - 1;
				 for(int i=n.length()-1;i>=0;i--) {
					 if(str.charAt(i)=='7') {
						 p3 = i;
						 str.deleteCharAt(i);
						 break;
					 }
				 }
				 tmp += n.length() - 1 - p3 - 1;
				 //str.deleteCharAt(str.length()-1);
				 str.deleteCharAt(str.length()-1);
				 //out.println(p3 + " " + p2);
				 //out.println(tmp);
				 boolean poss = true;
				 if(str.charAt(0)=='0') {
					 poss = false;
					 int ind = 1;
					 while(ind<str.length()) {
						 if(str.charAt(ind)!='0') {
							 poss = true;
							 tmp += ind;
							 //out.println(ind + " " +tmp);
							 break;
						 }
						 ind++;
					 } 
				 }
				 //out.println(tmp);
				 if(poss) {
					 if(tmp<swap) {
						 swap = tmp;
					 }
				 }
			 }
			 
			 ans:
			 if(swap!=Integer.MAX_VALUE) {
				 //swap++;
				 out.println(swap);
			 }
			 else {
				 out.println(-1);
			 }
			 }
			 out.close();
	
		}
	
		static long fac(long a) {
			long k = a;
			for (long i = 2; i < a; i++) {
				k = k * i;
			}
			System.out.println(k + " " + a);
	
			return a;
	
		}
	
		static class Pair implements Comparable<Pair> {
	
			long x, y;
			int i;
	
			Pair(long x, long y) {
				this.x = x;
				this.y = y;
				//this.i = i;
			}
	
			@Override
			public int compareTo(Pair o) {
				if (this.x != o.x) {
					return Long.compare(this.x, o.x);
				} else {
					return Long.compare(this.y, o.y);
					// return 0;
				}
			}
	
			@Override
			public boolean equals(Object o) {
				if (o instanceof Pair) {
					 Pair p = (Pair) o;
					return p.x == x && p.y == y && p.i == i;
				}
				return false;
			}
		}
	
		public static boolean isPal(String s) {
			for (int i = 0, j = s.length() - 1; i <= j; i++, j--) {
				if (s.charAt(i) != s.charAt(j)) {
					return false;
				}
			}
			return true;
		}
	
		public static String rev(String s) {
			 StringBuilder sb = new StringBuilder(s);
			sb.reverse();
			return sb.toString();
		}
	
		public static long gcd(long x, long y) {
			if (x % y == 0) {
				return y;
			} else {
				return gcd(y, x % y);
			}
		}
	
		public static int gcd(int x, int y) {
			if (x % y == 0) {
				return y;
			} else {
				return gcd(y, x % y);
			}
		}
	
		public static long gcdExtended(long a, long b, long[] x) {
	
			if (a == 0) {
				x[0] = 0;
				x[1] = 1;
				return b;
			}
			 long[] y = new long[2];
			 long gcd = gcdExtended(b % a, a, y);
	
			x[0] = y[1] - (b / a) * y[0];
			x[1] = y[0];
	
			return gcd;
		}
	
		public static int abs(int a, int b) {
			return Math.abs(a - b);
		}
	
		public static long abs(long a, long b) {
			return Math.abs(a - b);
		}
	
		public static int max(int a, int b) {
			if (a > b) {
				return a;
			} else {
				return b;
			}
		}
	
		public static int min(int a, int b) {
			if (a > b) {
				return b;
			} else {
				return a;
			}
		}
	
		public static long max(long a, long b) {
			if (a > b) {
				return a;
			} else {
				return b;
			}
		}
	
		public static long min(long a, long b) {
			if (a > b) {
				return b;
			} else {
				return a;
			}
		}
	
		public static long pow(long n, long p, long m) {
			long result = 1;
			if (p == 0) {
				return 1;
			}
			if (p == 1) {
				return n;
			}
			while (p != 0) {
				if (p % 2 == 1) {
					result *= n;
				}
				if (result >= m) {
					result %= m;
				}
				p >>= 1;
				n *= n;
				if (n >= m) {
					n %= m;
				}
			}
			return result;
		}
	
		public static long pow(long n, long p) {
			long result = 1;
			if (p == 0) {
				return 1;
			}
			if (p == 1) {
				return n;
			}
			while (p != 0) {
				if (p % 2 == 1) {
					result *= n;
				}
				p >>= 1;
				n *= n;
			}
			return result;
		}
	
		static class InputReader {
	
			private  InputStream stream;
			private  byte[] buf = new byte[8192];
			private int curChar, snumChars;
			private SpaceCharFilter filter;
	
			public InputReader(InputStream stream) {
				this.stream = stream;
			}
	
			public int snext() {
				if (snumChars == -1) {
					throw new InputMismatchException();
				}
				if (curChar >= snumChars) {
					curChar = 0;
					try {
						snumChars = stream.read(buf);
					} catch ( IOException e) {
						throw new InputMismatchException();
					}
					if (snumChars <= 0) {
						return -1;
					}
				}
				return buf[curChar++];
			}
	
			public int nextInt() {
				int c = snext();
				while (isSpaceChar(c)) {
					c = snext();
				}
				int sgn = 1;
				if (c == '-') {
					sgn = -1;
					c = snext();
				}
				int res = 0;
				do {
					if (c < '0' || c > '9') {
						throw new InputMismatchException();
					}
					res *= 10;
					res += c - '0';
					c = snext();
				} while (!isSpaceChar(c));
				return res * sgn;
			}
	
			public long nextLong() {
				int c = snext();
				while (isSpaceChar(c)) {
					c = snext();
				}
				int sgn = 1;
				if (c == '-') {
					sgn = -1;
					c = snext();
				}
				long res = 0;
				do {
					if (c < '0' || c > '9') {
						throw new InputMismatchException();
					}
					res *= 10;
					res += c - '0';
					c = snext();
				} while (!isSpaceChar(c));
				return res * sgn;
			}
	
			public int[] nextIntArray(int n) {
				 int a[] = new int[n];
				for (int i = 0; i < n; i++) {
					a[i] = nextInt();
				}
				return a;
			}
	
			public long[] nextLongArray(int n) {
				 long a[] = new long[n];
				for (int i = 0; i < n; i++) {
					a[i] = nextLong();
				}
				return a;
			}
	
			public String readString() {
				int c = snext();
				while (isSpaceChar(c)) {
					c = snext();
				}
				 StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = snext();
				} while (!isSpaceChar(c));
				return res.toString();
			}
	
			public String nextLine() {
				int c = snext();
				while (isSpaceChar(c)) {
					c = snext();
				}
				 StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = snext();
				} while (!isEndOfLine(c));
				return res.toString();
			}
	
			public boolean isSpaceChar(int c) {
				if (filter != null) {
					return filter.isSpaceChar(c);
				}
				return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
			}
	
			private boolean isEndOfLine(int c) {
				return c == '\n' || c == '\r' || c == -1;
			}
	
			public interface SpaceCharFilter {
				public boolean isSpaceChar(int ch);
			}
		}
	}