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>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcount(s);
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int MAXN = 5e5 + 100;
const int MOD = 1e9 + 7;
const long long MAXV = 1e6;
const double eps = 1e-12;
const long long INF = 1e16;
inline string toStr(long long x) {
  string tmp = "";
  do tmp = char(x % 10 + '0') + tmp;
  while (x /= 10);
  return tmp;
}
inline long long toInt(string s) {
  long long res = 0;
  for (auto x : s) res = res * 10 + x - '0';
  return res;
}
inline string toBinStr(long long x) {
  string res = "";
  do res = (x % 2 ? "1" : "0") + res;
  while (x >>= 1LL);
  return res;
}
long long rnd(int k) {
  if (!k) return rand() % MAXV + 1;
  long long t = rand() % MAXV + 1;
  return (rand() % t) + (MAXV - t);
}
long long random_gen(int sign) {
  long long x = rnd(rand() % 2);
  long long s = rand() % 2;
  s = !s ? 1 : -1;
  return sign == 1 ? x : sign == -1 ? -x : s * x;
}
inline void debugArray(int a[], int n) {
  cerr << "array = ";
  for (int i = 0; i < n; ++i) cerr << a[i] << " ";
  cerr << "\n";
}
int digit[10];
vector<int> pos[10];
string s;
bool divisible() {
  if (digit[0] > 1) return true;
  if (digit[2] && digit[5]) return true;
  if (digit[0] && digit[5]) return true;
  if (digit[5] && digit[7]) return true;
}
int solve(int x, int y) {
  if (pos[x].size() && pos[y].size()) {
    int len = s.size(), res = 0;
    string cop = s;
    int lasty = pos[y].back();
    if (lasty == 0 && s[1] == '0') {
      int pos = 0;
      for (int i = (2), _b = (len - 1); i <= _b; i++)
        if (cop[i] != '0') {
          pos = i;
          break;
        }
      while (cop[1] == '0') {
        swap(cop[pos], cop[pos - 1]), --pos;
        ++res;
      }
    }
    while (lasty < len - 1) {
      swap(cop[lasty], cop[lasty + 1]);
      ++lasty, ++res;
    }
    for (int i = (len - 1), _b = (0); i >= _b; i--)
      if (cop[i] - '0' == x) {
        int need = 0;
        if (i == 0 && cop[1] == '0') {
          for (int j = (2), _b = (len - 1); j <= _b; j++)
            if (cop[j] != '0') {
              need = j - 1;
              if (j == len - 1) return 1e9;
              break;
            }
        }
        return res + need + len - 2 - i;
      }
  } else
    return 1e9;
}
int main() {
  cin >> s;
  if (s.size() == 1) return !printf("-1");
  long long n = toInt(s);
  if (n % 25 == 0) return !printf("0");
  for (auto x : s) ++digit[x - '0'];
  if (!divisible()) return !printf("-1");
  if (digit[0] >= s.size() - 1) return !printf("-1");
  for (int i = 0, _a = (s.size()); i < _a; ++i) pos[s[i] - '0'].push_back(i);
  int res = 1e9;
  int len = s.size();
  if (pos[0].size() > 1) {
    int x = pos[0].back(), y = pos[0][pos[0].size() - 2];
    res = len - 3 + len - x - y;
  }
  res = min(res, solve(2, 5));
  res = min(res, solve(5, 0));
  res = min(res, solve(7, 5));
  printf("%d", res == 1e9 ? -1 : res);
}