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;
#pragma GCC optimize("O3")
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c h, c n) {
  return {h, n};
}
template <class c>
auto dud(c* r) -> decltype(cerr << *r);
template <class c>
char dud(...);
struct muu {
  template <class c>
  muu& operator<<(const c&) {
    return *this;
  }
  muu& operator()() { return *this; }
};
constexpr int32_t fx[4][2] = {{0, 1}, {0, -1}, {1, 1}, {1, -1}};
constexpr int32_t fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},
                               {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
using ll = int64_t;
using ull = uint64_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
using vll = vector<ll>;
const uint32_t MAX_SEGMENT_ENDING = int32_t(1e5 + 1);
const uint32_t SEG_TREE_HEIGHT = (uint32_t)floor(log2(MAX_SEGMENT_ENDING)) + 1u;
const uint32_t SEG_TREE_SIZE = 1u << SEG_TREE_HEIGHT;
const uint32_t FIRST_LEAF = SEG_TREE_SIZE >> 1u;
template <typename ForwardIterator, typename T>
ForwardIterator largest_less_than_or_equal_to(ForwardIterator first,
                                              ForwardIterator last,
                                              const T& val) {
  ForwardIterator it = upper_bound(first, last, val);
  if (it == first) return nullptr;
  return --it;
}
template <typename T>
void minn(T& a, T b) {
  if (a > b) a = b;
}
template <typename T>
void maxx(T& a, T b) {
  if (a < b) a = b;
}
template <typename T>
T min(const T& a, const T& b, const T& c) {
  return min(min(a, b), c);
}
template <typename T>
T max(const T& a, const T& b, const T& c) {
  return max(max(a, b), c);
}
struct FindUnion {
  vector<int> rep;
  vector<int> rankk;
  FindUnion(int n) {
    rep.resize(n + 1);
    rankk.resize(n + 1);
    for (int i = 0; i <= n; i++) init(i);
  }
  void init(int x) {
    rep[x] = x;
    rankk[x] = 0;
  }
  int find(int x) {
    if (rep[x] != x) rep[x] = find(rep[x]);
    return rep[x];
  }
  void unia(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rankk[rx] > rankk[ry]) {
      rep[ry] = rx;
    } else {
      rep[rx] = ry;
      if (rankk[ry] == rankk[rx]) rankk[ry]++;
    }
  }
};
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
vector<bool> sieve_of_eratosthenes(int n) {
  vector<bool> is_prime(n);
  fill(is_prime.begin(), is_prime.end(), true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; (uint64_t)i * i < is_prime.size(); i++) {
    if (is_prime[i]) {
      for (int j = i * i; j < is_prime.size(); j += i) is_prime[j] = false;
    }
  }
  return is_prime;
}
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
constexpr int32_t MAXN = int32_t(2e5 + 10);
constexpr int32_t INF = int32_t(2e9);
constexpr int64_t LLINF = (int64_t)1e15;
constexpr int64_t MOD = (int64_t)1e9 + 7;
int n;
map<int, pair<int, int>> mapping;
void solve() {
  string s;
  cin >> s;
  int ans = INF;
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] != '2' && s[i] != '5' && s[i] != '0') continue;
    for (int j = s.length() - 1; j >= 0; j--) {
      string t = s;
      int curr = 0;
      for (int k = i; k < s.length() - 1; k++) {
        swap(t[k], t[k + 1]);
        curr++;
      }
      for (int k = j; k < s.length() - 2; k++) {
        swap(t[k], t[k + 1]);
        curr++;
      }
      int n0 = -1;
      for (int k = 0; k < s.length() - 2; k++)
        if (t[k] != '0') {
          n0 = k;
          break;
        }
      if ((t[s.length() - 1] == '5' && t[s.length() - 2] == '2') ||
          (t[s.length() - 1] == '0' && t[s.length() - 2] == '0') ||
          (t[s.length() - 1] == '0' && t[s.length() - 2] == '5') ||
          (t[s.length() - 1] == '5' && t[s.length() - 2] == '7')) {
        if (n0 == -1 && t[0] == '0') {
          continue;
        }
        for (int k = n0; k > 0; k--) {
          swap(t[k], t[k - 1]);
          curr++;
        }
        ans = min(ans, curr);
      }
    }
  }
  if (ans == INF)
    cout << "-1";
  else
    cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}