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>
int requires_substitute(char string[], int index1, int index2) {
  if (index1 != 0 && index2 != 0) return 0;
  if (index1 == 1 || index2 == 1) {
    if (string[2] == '0') return 1;
  }
  if (string[1] == '0') return 1;
}
int requires_substitute_fifty(char string[], int index1, int index2) {
  if (index1 == 0 && index2 != 1 && string[1] == '0')
    return 1;
  else
    return 0;
}
int substitute(char string[], int index1, int index2, int size) {
  int res = -1;
  for (int i = 0; i < size; i++) {
    if (i != index1 && i != index2 && string[i] != '0') {
      res = i;
      break;
    }
  }
  return res;
}
int main() {
  char string[20];
  scanf("%s", string);
  int nums[5];
  for (int i = 0; i < 5; i++) {
    nums[i] = -1;
  }
  int switchZero = 1;
  int size = strlen(string);
  for (int i = 0; i < size; i++) {
    if (string[i] == '2') {
      nums[0] = i;
    } else if (string[i] == '5') {
      nums[1] = i;
    } else if (string[i] == '7') {
      nums[2] = i;
    } else if (string[i] == '0') {
      if (switchZero) {
        nums[3] = i;
        switchZero = 0;
      } else {
        nums[4] = i;
        switchZero = 1;
      }
    }
  }
  if (nums[3] > nums[4] || nums[4] == -1) {
    int tmp = nums[3];
    nums[3] = nums[4];
    nums[4] = tmp;
  }
  int steps[4];
  for (int i = 0; i < 4; i++) steps[i] = -1;
  if (nums[1] != -1) {
    if (nums[0] != -1) {
      int step_count = 0;
      if (size > 2 && requires_substitute(string, nums[1], nums[0])) {
        int sub = substitute(string, nums[1], nums[0], size);
        if (sub != -1) {
          step_count += sub;
          if (sub > nums[0]) step_count--;
          if (sub > nums[1]) step_count--;
        }
      }
      if (nums[1] < nums[0]) {
        step_count++;
      }
      step_count += size - nums[1] - 1;
      step_count += size - nums[0] - 2;
      steps[0] = step_count;
    }
    if (nums[2] != -1) {
      int step_count = 0;
      if (size > 2 && requires_substitute(string, nums[1], nums[2])) {
        int sub = substitute(string, nums[1], nums[2], size);
        if (sub != -1) {
          step_count += sub;
          if (sub > nums[2]) step_count--;
          if (sub > nums[1]) step_count--;
        }
      }
      if (nums[1] < nums[2]) {
        step_count++;
      }
      step_count += size - nums[1] - 1;
      step_count += size - nums[2] - 2;
      steps[1] = step_count;
    }
    if (nums[4] != -1) {
      int step_count = 0;
      if (size > 2 && requires_substitute_fifty(string, nums[1], nums[4])) {
        int sub = substitute(string, nums[1], nums[4], size);
        if (sub != -1) {
          step_count += sub;
        }
      }
      if (nums[1] > nums[4]) {
        step_count++;
      }
      step_count += size - nums[1] - 1;
      step_count += size - nums[4] - 2;
      steps[2] = step_count;
    }
  }
  if (nums[3] != -1 && nums[4] != -1) {
    int step_count = 0;
    step_count += size - nums[3] - 1;
    step_count += size - nums[4] - 2;
    steps[3] = step_count;
  }
  int min = -1;
  for (int i = 0; i < 4; i++) {
    if (steps[i] != -1) {
      if (min == -1 || steps[i] < min) {
        min = steps[i];
      }
    }
  }
  printf("%d", min);
}