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;
int main() {
  pair<int, int> DP[] = {make_pair(5, 0), make_pair(2, 5), make_pair(7, 5),
                         make_pair(10, 0)};
  int m1[] = {33, 36, 160, 1025}, i, P = 3777777, j, k;
  string R, m2 = "0257";
  set<int> d, d1(m1, m1 + 4);
  for (i = 0; i < 4; i++) d.insert(m2[i] - '0');
  d.insert(10);
  cin >> R;
  int N = R.size(), m, f = 0, T = 0, L, Rt;
  map<int, int> DM;
  for (i = N - 1; i >= 0 && d.size(); i--) {
    int K = R[i] - '0';
    K += f * (R[i] == '0');
    if (K == 0) f = 10;
    if (!d.count(K)) continue;
    d.erase(K);
    DM[K] = i;
    T |= 1 << K;
    for (j = 0; j < 4; j++)
      if (d1.count(m1[j] & T)) {
        d1.erase(m1[j]);
        L = DM[DP[j].first];
        Rt = DM[DP[j].second];
        m = 2 * N - Rt - L - 3 + (Rt < L);
        if ((L == 0 || Rt == 0) && j > 0 && j < 3) {
          for (k = 1;; k++)
            if (R[k] != '0') break;
          m += k - 1;
        }
        if (m < P) P = m;
      }
  }
  if (P == 3777777) P = -1;
  cout << P;
}