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;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream &operator<<(ostream &out, const vector<A> &a) {
  for (const A &it : a) out << it << " ";
  return out;
}
template <class A, class B>
istream &operator>>(istream &in, pair<A, B> &a) {
  return in >> a.first >> a.second;
}
template <class A>
istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a) in >> i;
  return in;
}
string s;
vector<long long> v[10];
long long n;
string f1(string s, char c) {
  long long idx = (1e18);
  for (long long i = 0; i < n; i++)
    if (s[i] == c) idx = i;
  for (long long i = idx; i < n - 1; i++) swap(s[i], s[i + 1]);
  return s;
}
string f2(string s, char c) {
  long long idx = (1e18);
  for (long long i = 0; i < n - 1; i++)
    if (s[i] == c) idx = i;
  for (long long i = idx; i < n - 2; i++) swap(s[i], s[i + 1]);
  return s;
}
long long f25() {
  if (v[2].empty() || v[5].empty()) return (1e18);
  long long a = v[2][0], b = v[5][0];
  long long cnt = 0;
  if ((a == n - 1 || b == n - 1) && s[1] == '0') {
    string A = f1(s, '5');
    A = f2(A, '2');
    for (long long i = 0; i < n; i++) {
      if (A[i] != '0') {
        cnt = i;
        break;
      }
    }
    if (cnt > n - 3) return (1e18);
  }
  if (a > b) {
    return a + b - 1 + cnt;
  } else {
    return a + b + cnt;
  }
}
long long f50() {
  if (v[5].empty() || v[0].empty()) return (1e18);
  long long a = v[5][0], b = v[0][0];
  long long cnt = 0;
  if ((a == n - 1 || b == n - 1) && s[1] == '0' && s != "50") {
    string A = f1(s, '0');
    A = f2(A, '5');
    for (long long i = 0; i < n; i++) {
      if (A[i] != '0') {
        cnt = i;
        break;
      }
    }
    if (cnt > n - 3) return (1e18);
  }
  if (a > b) {
    return a + b - 1 + cnt;
  } else {
    return a + b + cnt;
  }
}
long long f75() {
  if (v[7].empty() || v[5].empty()) return (1e18);
  long long a = v[7][0], b = v[5][0];
  long long cnt = 0;
  if ((a == n - 1 || b == n - 1) && s[1] == '0') {
    string A = f1(s, '5');
    A = f2(A, '7');
    for (long long i = 0; i < n; i++) {
      if (A[i] != '0') {
        cnt = i;
        break;
      }
    }
    if (cnt > n - 3) return (1e18);
  }
  if (a > b) {
    return a + b - 1 + cnt;
  } else {
    return a + b + cnt;
  }
}
long long f00() {
  if (v[0].size() < 2) return (1e18);
  long long a = v[0][0], b = v[0][1];
  bool safe = 0;
  for (char c : s) {
    if (c != '0') safe = 1;
  }
  if (!safe) return (1e18);
  long long cnt = 0;
  string A = f1(s, '0');
  A = f2(A, '0');
  for (long long i = 0; i < n; i++) {
    if (A[i] != '0') {
      cnt = i;
      break;
    }
  }
  return a + b - 1 + cnt;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  n = s.size();
  for (long long i = 0; i < n; i++) v[s[i] - '0'].push_back(n - i - 1);
  for (long long i = 0; i < 10; i++) sort((v[i]).begin(), (v[i]).end());
  long long ans = min({f25(), f50(), f75(), f00()});
  if (ans == (1e18)) ans = -1;
  cout << ans;
}