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 T>
void re(T& x) {
  cin >> x;
}
template <class T1, class T2>
void re(pair<T1, T2>& x) {
  re(x.first);
  re(x.second);
}
template <class T>
void re(vector<T>& x) {
  for (long i = 0; i < x.size(); i++) {
    re(x[i]);
  }
}
template <class T>
void re(deque<T>& x) {
  for (long i = 0; i < x.size(); i++) {
    re(x[i]);
  }
}
template <class T1, class T2>
pair<T1, T2> mp(T1& x, T2& z) {
  return make_pair(x, z);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long n, ans = 1e9, x, z;
  string s;
  cin >> s;
  n = s.length();
  long vis[10] = {};
  bool ok1 = false, ok2 = false, ok3 = false;
  long p1 = -1, p2 = -1, p3 = -1;
  vector<long> pos[10];
  for (long i = 0; i < n; i++) {
    if (s[i] != '0') {
      if (!ok1) {
        ok1 = true;
        p1 = i;
      } else if (!ok2) {
        ok2 = true;
        p2 = i;
      } else if (!ok3) {
        ok3 = true;
        p3 = i;
      }
    }
    vis[s[i] - '0']++;
    pos[s[i] - '0'].push_back(i);
  }
  if (vis[0] >= 2) {
    x = n - 1 - pos[0].back();
    z = pos[0].back();
    pos[0].pop_back();
    x += n - 2 - pos[0].back();
    pos[0].push_back(z);
    ans = min(ans, x);
  }
  if (vis[0] && vis[5] && (n == 2 || vis[0] < n - 1)) {
    x = n - 1 - pos[0].back();
    x += n - 1 - pos[5].back();
    if (pos[5].back() < pos[0].back()) {
      x--;
    }
    if (vis[0] > 1 && n > 2) {
      if (pos[5].back() == p1) {
        x += p2 - 1;
      }
    }
    ans = min(ans, x);
  }
  if (vis[2] && vis[5] && (n == 2 || vis[0] < n - 2)) {
    x = n - 1 - pos[5].back();
    x += n - 1 - pos[2].back();
    if (pos[2].back() < pos[5].back()) {
      x--;
    }
    if (vis[0] && n > 2) {
      if ((pos[5].back() == p1 && pos[2].back() == p2) ||
          (pos[2].back() == p1 && pos[5].back() == p2)) {
        x += p3 - 2;
      } else if ((pos[5].back() == p1) || (pos[2].back() == p1)) {
        x += p2 - 1;
      }
    }
    ans = min(ans, x);
  }
  if (vis[7] && vis[5] && (n == 2 || vis[0] < n - 2)) {
    x = n - 1 - pos[5].back();
    x += n - 1 - pos[7].back();
    if (pos[7].back() < pos[5].back()) {
      x--;
    }
    if (vis[0] && n > 2) {
      if ((pos[5].back() == p1 && pos[7].back() == p2) ||
          (pos[7].back() == p1 && pos[5].back() == p2)) {
        x += p3 - 2;
      } else if ((pos[5].back() == p1) || (pos[7].back() == p1)) {
        x += p2 - 1;
      }
    }
    ans = min(ans, x);
  }
  if (ans == 1e9) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}