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.util.*;

public class E implements Runnable{
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		long x = fs.nextLong();
		String str = Long.toString(x);
		int res = (int)1e9;

		String[] find = {"00", "25", "50", "75"};
		for(int k = 0; k < 4; k++) {
			for(int j = 0; j < str.length(); j++) {
				boolean cont = str.charAt(j) == find[k].charAt(1);
				if(!cont) continue;

				int ret = 0;
				char[] it = str.toCharArray();
				int atJ = j;
				boolean bad = false;
				while(atJ != str.length() - 1) {
					char next = it[atJ + 1];
					if(next == '0' && atJ == 0) {
						int y = shift(it);
						if(y == -1) {
							bad = true;
							break;
						}
						ret += y;
					}
					char now = it[atJ];
					it[atJ] = it[atJ+1];
					it[++atJ] = now;
					ret++;
				}
				if(bad) continue;
				
				int from = -1;
				for(int i = it.length - 2; i >= 0; i--) {
					if(it[i] == find[k].charAt(0)) {
						from = i;
						break;
					}
				}
				
				if(from == -1) continue;
				while(from != str.length() - 2) {
					char next = it[from + 1];
					if(next == '0' && from == 0) {
						int y = shift(it);
						if(y == -1) {
							bad = true;
							break;
						}
						ret += y;
					}
					char now = it[from];
					it[from] = it[from+1];
					it[++from] = now;
					ret++;
				}

				if(bad) continue;
				
//				System.out.println(j + " " + k + " " + new String(it) + " " + ret);
				
				res = Math.min(res, ret);
				
			}
		}

		if(res == (int)1e9) res = -1;
		out.println(res);
		out.close();
	}
	
	int shift(char[] a) {
		int idx = -1;
		for(int i = 1; i < a.length; i++) if(a[i] != '0') {
			idx = i;
			break;
		}
		if(idx == -1) return -1;
		int res = 0;
		while(idx != 1) {
			char now = a[idx];
			a[idx] = a[idx-1];
			a[--idx] = now;
			res++;
		}
		return res;
	}

	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 50; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}

	}

}