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;
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
using ll = long long int;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = vector<ll>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename U, typename V>
ostream& operator<<(ostream& s, const pair<U, V>& x) {
  s << "(" << x.first << ", " << x.second << ")";
  return s;
}
template <typename U>
ostream& operator<<(ostream& s, const vector<U>& x) {
  s << "[";
  bool was = false;
  for (auto it : x) {
    if (was) s << ", ";
    was = true;
    s << it;
  }
  s << "]";
  return s;
}
template <typename U>
ostream& operator<<(ostream& s, const deque<U>& x) {
  s << "[";
  bool was = false;
  for (auto it : x) {
    if (was) s << ", ";
    was = true;
    s << it;
  }
  s << "]";
  return s;
}
template <typename U, typename V>
ostream& operator<<(ostream& s, const map<U, V>& x) {
  s << "{";
  bool was = false;
  for (auto it : x) {
    if (was) s << ", ";
    was = true;
    s << it;
  }
  s << "}";
  return s;
}
template <typename U>
ostream& operator<<(ostream& s, const set<U>& x) {
  s << "{";
  bool was = false;
  for (auto it : x) {
    if (was) s << ", ";
    was = true;
    s << it;
  }
  s << "}";
  return s;
}
template <typename U>
ostream& operator<<(ostream& s, const multiset<U>& x) {
  s << "{";
  bool was = false;
  for (auto it : x) {
    if (was) s << ", ";
    was = true;
    s << it;
  }
  s << "}";
  return s;
}
ll expmod(ll a, ll b, ll mod) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
template <typename T>
T sqr(const T& x) {
  return x * x;
}
ll flog(const ll x) { return 63 - __builtin_clzll(x); }
template <typename T>
void sort(T& t) {
  sort(begin(t), end(t));
}
template <typename T>
void undupe(vector<T>& v) {
  sort(v);
  v.erase(unique(begin(v), end(v)), v.end());
}
template <typename T>
string binary(T x, int w = 8 * sizeof(T)) {
  string r;
  for (int i = 0; i < w; i++) r = (((T(1) << i) & x) ? '1' : '0') + r;
  return r;
}
}  // namespace
const ll MOD = 1000000009LL;
const ll INF = (ll)1e15;
const double EPS = 1e-8;
string s;
int n;
bool divis(const string& nxt) { return stoll(nxt) % 25 == 0; }
int bfs(int i, int j, int k) {
  map<string, int> dist;
  dist[s] = 0;
  queue<tuple<string, int, int, int, int>> q;
  q.push(make_tuple(s, i, j, k, 0));
  int d = 0;
  string cur;
  while (!q.empty()) {
    auto e = q.front();
    q.pop();
    tie(cur, i, j, k, d) = e;
    vi opt = {i, j, k};
    for (int cc = 0; cc < 3; cc++) {
      int pos = opt[cc];
      int delta = (cc == 0 ? -1 : 1);
      if (pos + delta < 0 || pos + delta >= n) continue;
      string nxt = cur;
      vi idx(n);
      iota(begin(idx), end(idx), 0);
      swap(nxt[pos], nxt[pos + delta]);
      swap(idx[pos], idx[pos + delta]);
      if (nxt[0] == '0') continue;
      if (dist.count(nxt)) continue;
      dist[nxt] = d + 1;
      if (divis(nxt)) {
        return d + 1;
      }
      q.push(make_tuple(nxt, idx[i], idx[j], idx[k], d + 1));
    }
  }
  return INT_MAX;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  n = (int)s.size();
  if (n == 1) {
    cout << -1 << '\n';
    return 0;
  }
  if (n == 2) {
    if (s == "25" || s == "50" || s == "75") {
      cout << 0 << '\n';
      return 0;
    }
    if (s == "52" || s == "57") {
      cout << 1 << '\n';
      return 0;
    }
    cout << -1 << '\n';
    return 0;
  }
  if (stoll(s) % 25 == 0) {
    cout << 0 << '\n';
    return 0;
  }
  int ans = INT_MAX;
  vi useful;
  if (s.rfind('5') != string::npos) useful.push_back(s.rfind('5'));
  if (s.rfind('7') != string::npos) useful.push_back(s.rfind('7'));
  if (s.rfind('2') != string::npos) useful.push_back(s.rfind('2'));
  int more = 2;
  for (int k = n - 1; k >= 0 && more; k--) {
    if (s[k] == '0') useful.push_back(k), more--;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (int)useful.size(); j++) {
      for (int k = j + 1; k < (int)useful.size(); k++) {
        if (i != useful[j] && i != useful[k])
          ans = min(ans, bfs(i, useful[j], useful[k]));
      }
    }
  }
  if (ans == INT_MAX)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
}