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 long long power(long long a, long long b) {
  long long x = 1;
  a = a % 1000000007ULL;
  while (b) {
    if (b & 1) x = (x * a) % 1000000007ULL;
    a = (a * a) % 1000000007ULL;
    b >>= 1;
  }
  return x;
}
inline long long inv(long long a) { return power(a, 1000000007ULL - 2); }
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
const int N = 1e5 + 5;
string s;
vector<int> v[12];
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++) {
    v[s[i] - '0'].push_back(i);
  }
  if (n < 2) {
    cout << "-1\n";
    return 0;
  }
  if (n == 2) {
    if (v[0].size() > 0 && v[5].size() > 0) {
      if (s[0] == '5')
        cout << "0\n";
      else
        cout << "1\n";
      return 0;
    }
    if (v[2].size() > 0 && v[5].size() > 0) {
      if (s[0] == '2')
        cout << "0\n";
      else
        cout << "1\n";
      return 0;
    }
    if (v[7].size() > 0 && v[5].size() > 0) {
      if (s[0] == '7')
        cout << "0\n";
      else
        cout << "1\n";
      return 0;
    }
    cout << "-1\n";
    return 0;
  }
  int ans = 10000;
  if (v[0].size() > 1) {
    int x = v[0].size();
    ans = min(ans, abs(n - 1 - v[0][x - 1]) + abs(n - 2 - v[0][x - 2]));
  }
  if (v[2].size() > 0 && v[5].size() > 0) {
    int x = v[2].size();
    int y = v[5].size();
    x = v[2][x - 1];
    y = v[5][y - 1];
    if (n != 3 || v[0].size() == 0) {
      int tmp = 0;
      string sss = s;
      for (int i = y; i < n - 1; i++) {
        sss[i] = sss[i + 1];
        tmp++;
      }
      sss[n - 1] = '5';
      for (int j = n - 2; j > -1; j--) {
        if (sss[j] == '2') {
          x = j;
          break;
        }
      }
      for (int i = x; i < n - 2; i++) {
        sss[i] = sss[i + 1];
        tmp++;
      }
      sss[n - 2] = '2';
      if (sss[0] == '0') {
        for (int j = 0; j < n; j++) {
          if (sss[j] == '0') tmp++;
        }
      }
      ans = min(tmp, ans);
    }
  }
  if (v[7].size() > 0 && v[5].size() > 0) {
    int x = v[7].size();
    int y = v[5].size();
    x = v[7][x - 1];
    y = v[5][y - 1];
    if (n != 3 || v[0].size() == 0) {
      int tmp = 0;
      string sss = s;
      for (int i = y; i < n - 1; i++) {
        sss[i] = sss[i + 1];
        tmp++;
      }
      sss[n - 1] = '5';
      for (int j = n - 2; j > -1; j--) {
        if (sss[j] == '7') {
          x = j;
          break;
        }
      }
      for (int i = x; i < n - 2; i++) {
        sss[i] = sss[i + 1];
        tmp++;
      }
      sss[n - 2] = '7';
      if (sss[0] == '0') {
        for (int j = 0; j < n; j++) {
          if (sss[j] == '0') tmp++;
        }
      }
      ans = min(tmp, ans);
    }
  }
  if (v[5].size() > 0 && v[0].size() > 0) {
    int x = v[5].size();
    int y = v[0].size();
    x = v[5][x - 1];
    y = v[0][y - 1];
    if (n != 3 || v[0].size() == 1) {
      int tmp = 0;
      string sss = s;
      for (int i = y; i < n - 1; i++) {
        sss[i] = sss[i + 1];
        tmp++;
      }
      sss[n - 1] = '0';
      for (int j = n - 2; j > -1; j--) {
        if (sss[j] == '5') {
          x = j;
          break;
        }
      }
      for (int i = x; i < n - 2; i++) {
        sss[i] = sss[i + 1];
        tmp++;
      }
      sss[n - 2] = '5';
      if (sss[0] == '0') {
        for (int j = 0; j < n; j++) {
          if (sss[j] == '0') tmp++;
        }
      }
      ans = min(tmp, ans);
    }
  }
  if (ans == 10000) {
    cout << "-1\n";
    return 0;
  }
  cout << ans << endl;
  return 0;
}