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;
string multiply(string num1, string num2) {
  int len1 = num1.size();
  int len2 = num2.size();
  if (len1 == 0 || len2 == 0) return "0";
  vector<int> result(len1 + len2, 0);
  int i_n1 = 0;
  int i_n2 = 0;
  for (int i = len1 - 1; i >= 0; i--) {
    int carry = 0;
    int n1 = num1[i] - '0';
    i_n2 = 0;
    for (int j = len2 - 1; j >= 0; j--) {
      int n2 = num2[j] - '0';
      int sum = n1 * n2 + result[i_n1 + i_n2] + carry;
      carry = sum / 10;
      result[i_n1 + i_n2] = sum % 10;
      i_n2++;
    }
    if (carry > 0) result[i_n1 + i_n2] += carry;
    i_n1++;
  }
  int i = result.size() - 1;
  while (i >= 0 && result[i] == 0) i--;
  if (i == -1) return "0";
  string s = "";
  while (i >= 0) s += std::to_string(result[i--]);
  return s;
}
int isPrime(long long int n) {
  if (n <= 1) return 0;
  for (long long int i = 2; i < n; i++)
    if (n % i == 0) return 0;
  return 1;
}
long long int modFact(long long int n, long long int p) {
  if (n >= p) return 0;
  long long int result = 1;
  for (long long int i = 1; i <= n; i++) result = (result * i) % p;
  return result;
}
bool isSubSequence(string str1, string str2, int m, int n) {
  if (m == 0) return true;
  if (n == 0) return false;
  if (str1[m - 1] == str2[n - 1])
    return isSubSequence(str1, str2, m - 1, n - 1);
  return isSubSequence(str1, str2, m, n - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  map<long long int, long long int> m;
  for (long long int i = 0; i < s.length(); i++) m[s[i] - '0']++;
  long long int ans = INT_MAX;
  string s1 = s;
  long long int f = 0;
  if (m[5] > 0 && m[0] > 0) {
    long long int x = -1;
    long long int y = -1;
    for (long long int i = s.length() - 1; i >= 0; i--) {
      if (s[i] == '0') {
        y = i;
        break;
      }
    }
    for (long long int i = y; i < s.length() - 1; i++) {
      swap(s[i], s[i + 1]);
      f++;
    }
    for (long long int i = s.length() - 2; i >= 0; i--) {
      if (s[i] == '5') {
        x = i;
        break;
      }
    }
    for (long long int i = x; i < s.length() - 2; i++) {
      f++;
      swap(s[i], s[i + 1]);
    }
    if (s[0] == '0') {
      long long int idx = -1;
      for (long long int i = 0; i < s.length() - 2; i++) {
        if (s[i] != '0') {
          idx = i;
          break;
        }
      }
      if (idx == -1)
        f = INT_MAX;
      else
        f = f + idx;
    }
    ans = min(ans, f);
  }
  f = 0;
  s = s1;
  if (m[0] > 1) {
    long long int x = -1;
    long long int y = -1;
    for (long long int i = s.length() - 1; i >= 0; i--) {
      if (s[i] == '0') {
        y = i;
        break;
      }
    }
    for (long long int i = y; i < s.length() - 1; i++) {
      swap(s[i], s[i + 1]);
      f++;
    }
    for (long long int i = s.length() - 2; i >= 0; i--) {
      if (s[i] == '0') {
        x = i;
        break;
      }
    }
    for (long long int i = x; i < s.length() - 2; i++) {
      f++;
      swap(s[i], s[i + 1]);
    }
    if (s[0] == '0') {
      long long int idx = -1;
      for (long long int i = 0; i < s.length() - 2; i++) {
        if (s[i] != '0') {
          idx = i;
          break;
        }
      }
      if (idx == -1)
        f = INT_MAX;
      else
        f = f + idx;
    }
    ans = min(ans, f);
  }
  f = 0;
  s = s1;
  if (m[2] > 0 && m[5] > 0) {
    long long int x = -1;
    long long int y = -1;
    for (long long int i = s.length() - 1; i >= 0; i--) {
      if (s[i] == '5') {
        y = i;
        break;
      }
    }
    for (long long int i = y; i < s.length() - 1; i++) {
      swap(s[i], s[i + 1]);
      f++;
    }
    for (long long int i = s.length() - 2; i >= 0; i--) {
      if (s[i] == '2') {
        x = i;
        break;
      }
    }
    for (long long int i = x; i < s.length() - 2; i++) {
      f++;
      swap(s[i], s[i + 1]);
    }
    if (s[0] == '0') {
      long long int idx = -1;
      for (long long int i = 0; i < s.length() - 2; i++) {
        if (s[i] != '0') {
          idx = i;
          break;
        }
      }
      if (idx == -1)
        f = INT_MAX;
      else
        f = f + idx;
    }
    ans = min(ans, f);
  }
  f = 0;
  s = s1;
  if (m[7] > 0 && m[5] > 0) {
    long long int x = -1;
    long long int y = -1;
    for (long long int i = s.length() - 1; i >= 0; i--) {
      if (s[i] == '5') {
        y = i;
        break;
      }
    }
    for (long long int i = y; i < s.length() - 1; i++) {
      swap(s[i], s[i + 1]);
      f++;
    }
    for (long long int i = s.length() - 2; i >= 0; i--) {
      if (s[i] == '7') {
        x = i;
        break;
      }
    }
    for (long long int i = x; i < s.length() - 2; i++) {
      f++;
      swap(s[i], s[i + 1]);
    }
    if (s[0] == '0') {
      long long int idx = -1;
      for (long long int i = 0; i < s.length() - 2; i++) {
        if (s[i] != '0') {
          idx = i;
          break;
        }
      }
      if (idx == -1)
        f = INT_MAX;
      else
        f = f + idx;
    }
    ans = min(ans, f);
  }
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
  return 0;
}