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 s;
int vi[10];
int z1 = -1, z2 = -1;
int two = -1, five = -1, seven = -1;
int solve(int a, int b) {
  int ans = 0;
  int len = s.length();
  int vb = -1;
  for (int i = len - 1; i >= 0; i--) {
    if (s[i] - '0' == b) {
      vb = i;
      break;
    }
  }
  if (vb != -1) {
    for (int i = vb; i < len - 1; i++) {
      swap(s[i], s[i + 1]);
      ans++;
    }
  }
  int va = -1;
  for (int i = len - 2; i >= 0; i--) {
    if (s[i] - '0' == a) {
      va = i;
      break;
    }
  }
  if (va != -1) {
    for (int i = va; i < len - 2; i++) {
      swap(s[i], s[i + 1]);
      ans++;
    }
  }
  int ind = 0;
  while (s[ind] - '0' == 0) {
    ind++;
  }
  for (int i = ind; i > 0; i--) {
    swap(s[i], s[i - 1]);
    ans++;
  }
  if (s[len - 1] - '0' == b && s[len - 2] - '0' == a) {
    return ans;
  }
  return 10000;
}
int main() {
  cin >> s;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    vi[s[i] - '0']++;
    if (s[i] - '0' == 0) {
      z2 = z1;
      z1 = i;
    }
    if (s[i] - '0' == 2) {
      two = i;
    }
    if (s[i] - '0' == 5) {
      five = i;
    }
    if (s[i] - '0' == 7) {
      seven = i;
    }
  }
  if (!((vi[2] && vi[5]) || (vi[5] && vi[0]) || (vi[7] && vi[5]) ||
        vi[0] >= 2)) {
    puts("-1");
    return 0;
  }
  if (two == len - 2 && five == len - 1 || five == len - 2 && z1 == len - 1 ||
      seven == len - 2 && five == len - 1 || z2 == len - 2 && z1 == len - 1) {
    puts("0");
    return 0;
  }
  if (two == len - 1 && five == len - 2 || five == len - 1 && z1 == len - 2 ||
      seven == len - 1 && five == len - 2) {
    puts("1");
    return 0;
  }
  int ans = 10000;
  string s1 = s;
  if (vi[2] && vi[5]) {
    ans = min(ans, solve(2, 5));
    s = s1;
  }
  if (vi[5] && vi[7]) {
    ans = min(ans, solve(7, 5));
    s = s1;
  }
  if (vi[5] && vi[0]) {
    ans = min(ans, solve(5, 0));
    s = s1;
  }
  if (vi[0] >= 2) {
    ans = min(ans, solve(0, 0));
    s = s1;
  }
  if (ans == 10000)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}