#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);
}
