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;
const int NR = 25;
void Min(int& x, int y) { x = min(x, y); }
void Max(int& x, int y) { x = max(x, y); }
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int n, ans = 0x3f3f3f3f;
char a[NR];
int la[NR];
int p, q;
int len(int x) {
  int res = 0;
  for (int i = x; i <= n; i++) {
    if (a[i] != '0') break;
    res++;
  }
  return res;
}
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  for (int i = n; i >= 1; i--)
    if (a[i] == '0' && (!p || !q)) ((!p) ? (p = i) : (q = i));
  if (p && q) Min(ans, (n - p) + (n - q) - 1);
  for (int i = 1; i <= n; i++) la[a[i] - '0'] = i;
  if (la[2] && la[5]) {
    if (la[2] == 1 && la[5] == 2 && len(3) < n - 2)
      Min(ans, n - 2 + n - 2 + len(3));
    else if (la[5] == 1 && la[2] == 2 && len(3) < n - 2)
      Min(ans, n - 2 + n - 2 + 1 + len(3));
    else if (la[2] == 1 && len(2) < n - 1 && la[5] > len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[5] - 1);
    else if (la[2] == 1 && len(2) < n - 2 && la[5] == len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[5] - 1);
    else if (la[5] == 1 && len(2) < n - 1 && la[2] > len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[2]);
    else if (la[5] == 1 && len(2) < n - 2 && la[2] == len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[2]);
    else
      Min(ans, n - la[2] + n - la[5] + (la[2] > la[5]) - 1);
  }
  if (la[7] && la[5]) {
    if (la[7] == 1 && la[5] == 2 && len(3) < n - 2)
      Min(ans, n - 2 + n - 2 + len(3));
    else if (la[5] == 1 && la[7] == 2 && len(3) < n - 2)
      Min(ans, n - 2 + n - 2 + 1 + len(3));
    else if (la[7] == 1 && len(2) < n - 1 && la[5] > len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[5] - 1);
    else if (la[7] == 1 && len(2) < n - 2 && la[5] == len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[5] - 1);
    else if (la[5] == 1 && len(2) < n - 1 && la[7] > len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[7]);
    else if (la[5] == 1 && len(2) < n - 2 && la[7] == len(2) + 2)
      Min(ans, len(2) + n - 1 + n - la[7]);
    else
      Min(ans, n - la[7] + n - la[5] + (la[7] > la[5]) - 1);
  }
  if (la[0] && la[5]) {
    if (la[5] == 1) {
      if (la[0] == len(2) + 1)
        Min(ans, n - la[0] + n - 1 + len(2) - 2);
      else
        Min(ans, n - la[0] + n - 1 + len(2) - 1);
    } else
      Min(ans, n - la[0] + n - la[5] + (la[5] > la[0]) - 1);
  }
  printf("%d\n", (ans == 0x3f3f3f3f) ? -1 : ans);
  return 0;
}