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 int read() {
  int x = 0, t = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') t = -1, ch = getchar();
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
  return x * t;
}
const int maxn = 2e5 + 5;
char a[30];
int num[30];
int b[20];
int check(int x, int y, int len) {
  if (b[x] == 0 || b[y] == 0) return -1;
  if (x == 0 && y == 0 && b[0] == 1) return -1;
  if (num[len - 1] == 0 && num[len - 2] == 0) return 0;
  if (num[len - 1] == x && num[len - 2] == y) return 1;
  int y_pos = -1, x_pos = -1;
  for (int i = len - 1; i >= 0; i--) {
    if (num[i] == y && y_pos == -1)
      y_pos = i;
    else if (num[i] == x && x_pos == -1)
      x_pos = i;
  }
  if (x_pos == len - 1) {
    if (!y_pos) {
      int zlen = 0;
      for (int i = 1; i < len; i++) {
        if (num[i] == 0)
          zlen++;
        else
          break;
      }
      return zlen + (len - 2 - y_pos) + 1;
    } else {
      return (len - 2 - y_pos) + 1;
    }
  }
  if (y == 0) {
    if (!x_pos) {
      int zlen = 0;
      for (int i = 1; i < len; i++) {
        if (num[i] == 0)
          zlen++;
        else
          break;
      }
      if (y_pos == x_pos + zlen)
        return zlen - 1 + (len - 1 - y_pos) + (len - 2 - x_pos);
      if (x_pos > y_pos)
        return zlen + (len - 1 - y_pos) + (len - 2 - x_pos) + 1;
      return zlen + (len - 1 - y_pos) + (len - 2 - x_pos);
    } else {
      if (x_pos > y_pos) return (len - 1 - y_pos) + (len - 2 - x_pos) + 1;
      return (len - 1 - y_pos) + (len - 2 - x_pos);
    }
  }
  if (!y_pos) {
    int zlen = 0;
    for (int i = 1; i < len; i++) {
      if (num[i] == 0)
        zlen++;
      else
        break;
    }
    if (x_pos > y_pos) return zlen + (len - 1 - y_pos) + (len - 2 - x_pos) + 1;
    return zlen + (len - 1 - y_pos) + (len - 2 - x_pos);
  } else if (!x_pos) {
    int zlen = 0;
    for (int i = 1; i < len; i++) {
      if (num[i] == 0)
        zlen++;
      else
        break;
    }
    if (x_pos > y_pos) return zlen + (len - 1 - y_pos) + (len - 2 - x_pos) + 1;
    return zlen + (len - 1 - y_pos) + (len - 2 - x_pos);
  } else {
    if (x_pos > y_pos) return (len - 1 - y_pos) + (len - 2 - x_pos) + 1;
    return (len - 1 - y_pos) + (len - 2 - x_pos);
  }
}
int main() {
  while (~scanf("%s", a)) {
    int len = strlen(a);
    memset(b, 0, sizeof b);
    for (int i = 0; i < len; i++) {
      num[i] = a[i] - '0';
      b[a[i] - '0']++;
    }
    int ans = 1e9;
    int x1 = check(0, 0, len);
    if (x1 != -1) ans = min(ans, x1);
    int x2 = check(2, 5, len);
    if (x2 != -1) ans = min(ans, x2);
    int x3 = check(7, 5, len);
    if (x3 != -1) ans = min(ans, x3);
    int x4 = check(5, 0, len);
    if (x4 != -1) ans = min(ans, x4);
    if (ans == 1e9)
      puts("-1");
    else
      printf("%d\n", ans);
  }
  return 0;
}