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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b == 0LL ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll mod_pow(ll base, ll power, ll mod) {
  base %= mod;
  ll ret = 1LL;
  while (power) {
    if (power & 1) ret = (ret * base) % mod;
    base = (base * base) % mod;
    power >>= 1;
  }
  return ret;
}
vector<ll> primes_global;
vector<ll> seive(ll _upper_bound = 10000000) {
  bitset<10000007> bs;
  bs.set();
  if (_upper_bound > 10000000) _upper_bound = 10000000;
  vector<ll> primes;
  ll _seive_size = _upper_bound;
  bs[0] = bs[1] = 0;
  for (ll i = 2; i <= _seive_size; i++) {
    if (bs[i]) {
      for (ll j = i * i; j <= _seive_size; j += i) bs[j] = 0;
      primes.push_back(i);
    }
  }
  primes_global = primes;
  return primes;
}
bool is_prime(ll _number) {
  if (primes_global.empty()) seive();
  for (int i = 0; primes_global[i] * primes_global[i] <= _number and
                  i < primes_global.size();
       i++) {
    if (_number % primes_global[i] == 0) return false;
  }
  return true;
}
vector<ll> prime_factors(ll _number) {
  if (primes_global.empty()) {
    seive();
  }
  vector<ll> factors;
  ll pf_idx = 0, pf = primes_global[pf_idx];
  if (is_prime(_number)) {
    factors.push_back(_number);
    return factors;
  }
  while (pf * pf <= _number) {
    if (_number % pf == 0) {
      factors.push_back(pf);
      while (_number % pf == 0) _number /= pf;
    }
    pf = primes_global[++pf_idx];
  }
  if (_number != 1) factors.push_back(_number);
  return factors;
}
const int mm = INT_MAX;
int func(string a, char first, char second) {
  int ret = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == first) {
      ret += i;
      for (int j = i; j > 0; j--) {
        swap(a[j], a[j - 1]);
      }
      break;
    }
  }
  for (int i = 1; i < a.size(); i++) {
    if (a[i] == second) {
      ret += i - 1;
      for (int j = i; j > 1; j--) {
        swap(a[j], a[j - 1]);
      }
      break;
    }
  }
  if (a.back() == '0') {
    bool f = 1;
    for (int i = a.size() - 1; i > 1; i--) {
      if (a[i] != '0') {
        for (int j = i; j < a.size() - 1; j++) {
          swap(a[j], a[j + 1]);
          ret++;
        }
        f = 0;
        break;
      }
    }
    if (f) return mm;
  }
  if (a[0] == first and a[1] == second)
    return ret;
  else
    return mm;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin.tie(0);
  string in;
  cin >> in;
  reverse(in.begin(), in.end());
  int ans = func(in, '0', '0');
  ans = min(ans, func(in, '5', '2'));
  ans = min(ans, func(in, '0', '5'));
  ans = min(ans, func(in, '5', '7'));
  if (ans == mm)
    cout << -1 << endl;
  else
    cout << ans << endl;
}