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;
char s[20], q[20], w[20];
int book[10], d, minn = 0x3f3f3f;
int qq() {
  if (book[2] == 0 || book[5] == 0) return 0x3f3f3f3f;
  int sum = 0;
  if (s[d - 1] != '5') {
    for (int i = book[5] - 1; i < d; i++) s[i] = s[i + 1];
    sum += d - book[5];
  }
  if (s[d - 2] != '2') {
    for (int i = d - 3; i >= 0; i--)
      if (s[i] == '2') {
        sum += d - 1 - (i + 1);
        for (int j = i; j < d - 2; j++) swap(s[j], s[j + 1]);
        break;
      }
  }
  int p = 0;
  while (s[p] == '0') p++;
  if (p < d - 2 || p == 0)
    sum += p;
  else
    sum = 0x3f3f3f3f;
  return sum;
}
int ww() {
  if (book[0] == 0 || book[5] == 0) return 0x3f3f3f3f;
  int sum = 0;
  if (q[d - 1] != '0') {
    for (int i = book[0] - 1; i < d; i++) q[i] = q[i + 1];
    sum += d - book[0];
  }
  q[d - 1] = '0';
  if (q[d - 2] != '5')
    for (int i = d - 3; i >= 0; i--)
      if (q[i] == '5') {
        sum += d - 1 - (i + 1);
        for (int j = i; j < d - 2; j++) swap(q[j], q[j + 1]);
        break;
      }
  int p = 0;
  while (q[p] == '0') p++;
  if (p < d - 2 || p == 0)
    sum += p;
  else
    sum = 0x3f3f3f3f;
  return sum;
}
int op() {
  if (book[7] == 0 || book[5] == 0) return 0x3f3f3f3f;
  int sum = 0;
  if (w[d - 1] != '5') {
    for (int i = book[5] - 1; i < d; i++) w[i] = w[i + 1];
    sum += d - book[5];
  }
  w[d - 1] = '5';
  if (w[d - 2] != '7') {
    for (int i = d - 3; i >= 0; i--)
      if (w[i] == '7') {
        for (int j = i; j < d - 2; j++) swap(w[j], w[j + 1]);
        sum += d - 1 - (i + 1);
        break;
      }
  }
  int p = 0;
  while (w[p] == '0') p++;
  if (p < d - 2 || p == 0)
    sum += p;
  else
    sum = 0x3f3f3f3f;
  return sum;
}
int main() {
  scanf("%s", s);
  d = strlen(s);
  strcpy(q, s);
  strcpy(w, s);
  int sum = 0, w = 0;
  for (int i = d - 1; i >= 0; i--) {
    if (s[i] == '0' && sum < 2) {
      w += i + 1;
      sum++;
    }
    if (book[s[i] - 48] == 0) book[s[i] - 48] = i + 1;
  }
  if (sum == 2)
    minn = min(min(min(qq(), ww()), op()), 2 * d - 1 - w);
  else
    minn = min(min(qq(), ww()), op());
  if (minn != 0x3f3f3f3f)
    printf("%d\n", minn);
  else
    printf("-1\n");
}