#include <bits/stdc++.h>
using namespace std;
int main() {
  string(s);
  cin >> (s);
  ;
  long long n = s.length();
  long long c0 = 0, c5 = 0, c2 = 0;
  for (long long i = 0; i < (n); i++) {
    if (s[i] == '0') c0++;
    if (s[i] == '2') c2++;
    if (s[i] == '5') c5++;
    if (s[i] == '7') {
      s[i] = '2';
      c2++;
    }
  }
  long long mini = (long long)1e18;
  if (c0 >= 2) {
    long long val = 0, seen = 0;
    for (long long i = n - 1; i >= (0); i--) {
      if (s[i] == '0') {
        seen++;
        val += (n - 1) - i;
      }
      if (seen == 2) break;
    }
    mini = min(mini, val - 1);
  }
  if (c0 >= 1 && c5 >= 1) {
    long long idx0 = 0, idx5 = 0;
    long long val = 0;
    for (long long i = n - 1; i >= (0); i--) {
      if (s[i] == '0') {
        idx0 = i;
        break;
      }
    }
    for (long long i = n - 1; i >= (0); i--) {
      if (s[i] == '5') {
        idx5 = i;
        break;
      }
    }
    if (idx5 < idx0) {
      val += (n - 1) - idx0;
      val += (n - 2) - idx5;
    } else {
      val += (n - 1) - idx0;
      val += (n - 2) - idx5;
      val += 1;
    }
    mini = min(mini, val);
  }
  if (c2 >= 1 && c5 >= 1) {
    long long idx5 = 0, idx2 = 0;
    long long val = 0;
    for (long long i = n - 1; i >= (0); i--) {
      if (s[i] == '5') {
        idx5 = i;
        break;
      }
    }
    for (long long i = n - 1; i >= (0); i--) {
      if (s[i] == '2') {
        idx2 = i;
        break;
      }
    }
    if (idx2 < idx5) {
      val += (n - 1) - idx5;
      val += (n - 2) - idx2;
    } else {
      val += (n - 1) - idx5;
      val += (n - 2) - idx2;
      val += 1;
    }
    if (idx5 == 0) {
      long long k = 0;
      for (long long i = 1; i < (n); i++)
        if (s[i] == '0')
          k++;
        else
          break;
      val += k;
    }
    mini = min(mini, val);
  }
  printf("%lld\n", mini == (long long)1e18 ? (long long)(-1) : mini);
  return 0;
}
