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;
inline void setmin(int &x, int y) {
  if (y < x) x = y;
}
inline void setmax(int &x, int y) {
  if (y > x) x = y;
}
inline void setmin(long long &x, long long y) {
  if (y < x) x = y;
}
inline void setmax(long long &x, long long y) {
  if (y > x) x = y;
}
const int N = 200000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int solve(string s, char c1, char c2) {
  int n = (int)s.size();
  int p1 = -1, p2 = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == c1) p1 = i;
    if (s[i] == c2) p2 = i;
  }
  if (p1 == -1 || p2 == -1) return inf;
  if ((int)s.size() == 2) return (p1 < p2 ? 0 : 1);
  int f = -1;
  for (int i = 0; i < n; i++)
    if (i != p1 && i != p2 && s[i] != '0') {
      f = i;
      break;
    }
  if (f == -1) return inf;
  int res = f;
  if (p1 < f) p1++;
  if (p2 < f) p2++;
  if (p1 > p2) {
    res++;
    swap(p1, p2);
  }
  res += (n - 1) - p2 + (n - 2) - p1;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  string s;
  cin >> s;
  int n = (int)s.size();
  if ((int)s.size() == 1) {
    cout << -1 << "\n";
    return 0;
  }
  int ans = inf;
  vector<int> zero;
  for (int i = 0; i < n; i++)
    if (s[i] == '0') zero.push_back(i);
  if ((int)zero.size() >= 2)
    setmin(ans, (n - 1) - zero[(int)zero.size() - 1] + (n - 2) -
                    zero[(int)zero.size() - 2]);
  vector<int> g = {25, 50, 75};
  for (int x : g) setmin(ans, solve(s, '0' + x / 10, '0' + x % 10));
  cout << (ans != inf ? ans : -1) << "\n";
  return 0;
}