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.
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
  os << "(";
  os << v.first << "," << v.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  long long sz = v.size();
  for (long long i = 0; i < sz; ++i) {
    os << v[i];
    if (i != sz - 1) os << ",";
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  T last = *v.rbegin();
  os << "[";
  for (auto it : v) {
    os << it;
    if (it != last) os << ",";
  }
  os << "]\n";
  return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
  for (auto it : v) {
    os << it.first << " : " << it.second << "\n";
  }
  return os;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) {
      res = (res * a) % 1000000007;
    }
    b /= 2;
    a = (a * a) % 1000000007;
  }
  return res;
}
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
string s;
long long solve(char First, char Second) {
  long long posF = -1, posS = -1;
  long long n = s.size();
  for (long long i = n - 1; i >= 0; --i) {
    if (s[i] == Second) {
      posS = i;
      break;
    }
  }
  if (posS == -1) return 1000000007;
  for (long long i = n - 1; i >= 0; --i) {
    if (s[i] == First && i != posS) {
      posF = i;
      break;
    }
  }
  if (posF == -1) return 1000000007;
  long long cnt = 0;
  if (posF == 0 || posS == 0) {
    if (n <= 2) {
    } else {
      long long idx = 0;
      while (idx < n) {
        if (idx == posF or idx == posS)
          ++idx;
        else if (s[idx] == '0') {
          ++cnt, ++idx;
        } else
          break;
      }
      if (idx == n) return 1000000007;
    }
  }
  cnt += 2 * n - 3 - posF - posS;
  if (posF > posS) ++cnt;
  return cnt;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  long long ans =
      min({solve('0', '0'), solve('2', '5'), solve('5', '0'), solve('7', '5')});
  if (ans == 1000000007) ans = -1;
  cout << ans << endl;
  return 0;
}
